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
|
Sub RemplirTableauWordDepuisDonnéesExcel()
Dim DocWord As Word.Document
Dim AppWord As Word.Application
Dim nomWord As String
Set AppWord = New Word.Application
AppWord.Visible = True
nomWord = "Chemin\fichier.docx"
Set DocWord = AppWord.Documents.Add
DocWord.SaveAs nomWord
ActiveDocument.Tables.Add Range:=ActiveDocument.Range(Start:=0, End:=0), numrows:=1, numcolumns:=5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
With DocWord.Tables(1)
.Cell(0, 1).Range.InsertAfter "A"
.Cell(0, 2).Range.InsertAfter "B"
.Cell(0, 3).Range.InsertAfter "C"
.Cell(0, 4).Range.InsertAfter "D"
.Cell(0, 5).Range.InsertAfter "E"
End With
DocWord.Application.ActiveDocument.Save
AppWord.Application.Quit
End Sub |
Partager