1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
   |  
        Dim WordAppli As Word.Application
        Dim MergeDoc As Word.Document
        Try
 
            Dim TemplateFile As Object = "chemin fichier doc"
            Dim DataSourceFile As Object = "chemin fichier txt"
            Dim ObjMiss As Object = System.Reflection.Missing.Value 'Type.Missing
            Dim OFalse As Object = False
            Dim OTrue As Object = True
 
            'Starting the Word Application
            WordAppli = New Word.Application
            WordAppli.Visible = False
            'Open the Template file
            MergeDoc = WordAppli.Documents.Open(TemplateFile)
            'Open the Data Source
            Dim DSFormat As Object = Word.WdOpenFormat.wdOpenFormatText
            MergeDoc.MailMerge.OpenDataSource(DataSourceFile, DSFormat, OFalse, ObjMiss, OTrue, OFalse, ObjMiss, ObjMiss, ObjMiss, ObjMiss, ObjMiss, ObjMiss, ObjMiss, ObjMiss, ObjMiss, ObjMiss)
            'Perform the Mail Merge
            MergeDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter
            MergeDoc.MailMerge.SuppressBlankLines = False
            MergeDoc.MailMerge.Execute(OFalse)
 
          Catch exCom As COMException
            ' traitement
        Catch ex As Exception
            'traitement
        Finally
            'Close the template document.
            If Not MergeDoc Is Nothing Then MergeDoc.Close()
            If Not WordAppli Is Nothing Then WordAppli.Quit()
            MergeDoc = Nothing
            WordAppli = Nothing
        End Try | 
Partager