Créer un tableau word à partir d'excel
Bonjour,
Je voudrais créer un tableau avec 1 ligne et 5 colonnes vers word.
J'arrive bien à créer mon tableau la 1ère fois mais si je reéxécute la macro une deuxième fois il me met Le serveur distant n'existe pas ou n'est pas disponible (erreur 462). C'est du a quoi ?
Et Range:=ActiveDocument.Range(Start:=0, End:=0)
C'est sa correspond à quelles cellules dans word ?
Code:
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 |