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
| Option Explicit
Sub Remplir_ChampsWord_Selection()
Dim WordApp As Object
Dim WordDoc As Object
Dim iCol As Long
Dim Cel As Range, Inter As Range
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False
For Each Cel In Selection.Cells
Set Inter = Application.Intersect(Cel, Feuil1.[Liste])
If Not Inter Is Nothing Then
Set WordDoc = WordApp.Documents.Open(ThisWorkbook.Path & "\" & "Modele.doc")
For iCol = 1 To 8
WordDoc.Fields(iCol).Result.Text = Trim$(Feuil1.Cells(Cel.Row, iCol))
Next iCol
WordDoc.SaveAs Filename:=ThisWorkbook.Path & "\Test\" & "SP " & Format(Cel.Row - 1, "000") & ".doc"
Set WordDoc = Nothing
End If
Next Cel
WordApp.Quit
Set WordApp = Nothing
Feuil1.Range("A1").Select
End Sub |
Partager