Create multiple Base Word Document letters from Excel Table.
Change the path to where you save the workbook and base word document
Code
Option Explicit
Sub fillwordform()
Dim appword As Object
Dim Doc As Object
Dim Path As String
Dim lngRow As Long
Dim lngCount As Long
Path = "C:\Users\user\Documents\New folder 3\Generate Letter.docx" ' Change to your path
Set appword = CreateObject("Word.Application")
For lngRow = 2 To Sheets("Record Set").Cells(Rows.Count, 1).End(xlUp).Row
Set Doc = appword.Documents.Open(Path, , True)
With Doc
.FormFields("strName").Result = Sheets("Record Set").Cells(lngRow, 4).Value
.FormFields("strName1").Result = Sheets("Record Set").Cells(lngRow, 4).Value
.FormFields("strAddress1").Result = Sheets("Record Set").Cells(lngRow, 5).Value
.FormFields("strAddress2").Result = Sheets("Record Set").Cells(lngRow, 6).Value
.FormFields("strAddress3").Result = Sheets("Record Set").Cells(lngRow, 7).Value
.FormFields("strAddress4").Result = Sheets("Record Set").Cells(lngRow, 8).Value
.FormFields("strAddress5").Result = Sheets("Record Set").Cells(lngRow, 9).Value
.FormFields("strMake").Result = Sheets("Record Set").Cells(lngRow, 1).Value
.FormFields("strModel").Result = Sheets("Record Set").Cells(lngRow, 2).Value
.FormFields("strMake1").Result = Sheets("Record Set").Cells(lngRow, 1).Value
.FormFields("strModel1").Result = Sheets("Record Set").Cells(lngRow, 2).Value
.FormFields("strDescription").Result = Sheets("Record Set").Cells(lngRow, 3).Value
End With
lngCount = lngCount + 1
Doc.SaveAs "C:\Users\user\Documents\New folder 3\pTest" & lngCount & ".docx" ' Change to your path
Doc.Close
Next lngRow
Set Doc = Nothing
Set appword = Nothing
End Sub
Display More