Option Explicit
Sub CréationFicheBase()
'nécéssite d'activer la référence Microsoft Word xx.x Object Library
Dim WordApp As Word.Application, WordDoc As Word.Document
Dim i&, j&, pos&, NomDoc$, s As Object
Application.ScreenUpdating = 0
Set WordApp = CreateObject("word.application")
On Error Resume Next
For j = 3 To [A65536].End(xlUp).Row
NomDoc = ThisWorkbook.Path & "\" & Cells(j, 1) & ".doc"
Set WordDoc = WordApp.Documents.Open(ThisWorkbook.Path & "\" & "Template.doc") 'A Modifier
WordDoc.SaveAs2 NomDoc
For i = 1 To 23
Set s = WordDoc.Bookmarks("Signet" & i)
If s Is Nothing Then GoTo Suite
WordDoc.Activate
s.Select
WordApp.Options.ReplaceSelection = True
If Cells(j, i) <> "" Then
WordApp.Selection.TypeText Cells(j, i)
pos = WordApp.Selection.Range.End
Set s = WordDoc.Range(pos - Len(Cells(j, i)), pos)
Else
WordApp.Selection.TypeText " "
pos = WordApp.Selection.Range.End
Set s = WordDoc.Range(pos - 1, pos)
End If
WordDoc.Bookmarks.Add "Signet" & i, s
On Error GoTo 0
Suite:
Next i
WordDoc.Close True
Next j
WordApp.Quit
Beep
Application.ScreenUpdating = -1
End Sub