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
| Sub ImportWord()
Dim DocWord As Word.Document
Dim Lig As Long
'ouvrir le modèle
Set DocWord = GetObject("\test newsletterV2.docm", NewTemplate:=False, DocumentType:=0)
With Worksheets("Newsencours")
For Lig = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
If DocWord.Bookmarks.Exists("BKTitre_" & .Cells(Lig, 1).Value) Then ' on vérifie que le chapitre existe
DocWord.Bookmarks("BKTitre_" & .Cells(Lig, 1).Value).Range.Text = .Cells(Lig, 2).Value
DocWord.Bookmarks("BKAuteur_" & .Cells(Lig, 1).Value).Range.Text = .Cells(Lig, 5).Value
DocWord.Bookmarks("BKSource_" & .Cells(Lig, 1).Value).Range.Text = .Cells(Lig, 6).Value
DocWord.Bookmarks("BKDate_" & .Cells(Lig, 1).Value).Range.Text = .Cells(Lig, 7).Value
Else
'DocWord.Bookmarks("A_CLASSER").Range.Paste
'DocWord.Bookmarks("A_CLASSER").Range.InsertAfter vbCrLf
End If
Next Lig
End With
DocWord.Application.Visible = True
DocWord.Application.Activate
Set DocWord = Nothing
End Sub |
Partager