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 36 37 38 39 40 41
| Sub enregistrer_doc_word_en_boucle()
'
' enregistrer_doc_word_en_boucle Macro
'
Application.Goto Reference:="enregistrer_doc_word_en_boucle"
Dim wk_fichier As Workbook
Dim ws_feuil As Worksheet
Dim lstrw As Long
Dim wordapp As Object
Dim wordDoc As Object
Dim path_file As String
Dim dossier_fichier As String
Dim chemin_word As String
Set wk_fichier = ActiveWorkbook
Set ws_feuil = wk_fichier.Worksheets(1)
dossier_fichier = "C:\Users\session\Desktop"
path_file = "C:\Users\session\Desktop\attestation.docx"
Set wordapp = CreateObject("word.application")
wordapp.Visible = True
lstrw = ws_feuil.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lstrw
Set wordDoc = wordapp.Documents.Open(path_file)
With wordDoc
.Bookmarks("Nom").Range.Text = ws_feuil.Cells(i, 4) erreur 5941 le membre de la collection requis n'existe pas
.Bookmarks("fonction").Range.Text = ws_feuil.Cells(i, 11)
.Bookmarks("date").Range.Text = ws_feuil.Cells(i, 12)
End With
wordDoc.SaveAs "" & chemin_word
wordDoc.Close
Next
wordapp.Quit
MsgBox ("Fin de procédure")
chemin_word = dossier_fichier & "\" & ws_feuil.Cells(i, 4) & "_" & ws_feuil.Cells(i, 10) & ".docx"
End Sub |
Partager