Sub OpenWordAndFillDataWithoutBookmarks()
Dim wdApp As Object
Dim wdDoc As Object
Dim wb As Workbook
Dim ws As Worksheet
Dim filePath As String
Dim wordDocPath As String
Dim rowIndex As Long
Dim i As Integer
Dim textToInsert As String
' Define paths
filePath = ThisWorkbook.Path & "\WAWASE JHS_A_B-7A.xlsm" ' Path to the workbook
wordDocPath = ThisWorkbook.Path & "\SBAFORM BS7A.docx" ' Path to the Word document
' Open the target workbook
Set wb = Workbooks.Open(filePath)
Set ws = wb.Sheets("MASTERSHEET")
' Get the data row to insert (update the rowIndex if necessary)
rowIndex = 2 ' Example: Insert data from the 2nd row of the worksheet
' Start Word and open the document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If wdApp Is Nothing Then Set wdApp = CreateObject("Word.Application")
On Error GoTo 0
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(wordDocPath)
' Iterate through cells in the row and add data to the Word document
With wdDoc
For i = 1 To ws.UsedRange.Columns.Count ' Loop through each column in the row
textToInsert = ws.Cells(rowIndex, i).Value ' Get the data from the cell
.Content.InsertAfter textToInsert & vbNewLine ' Insert data with a newline
Next i
End With
' Close the workbook (optional)
wb.Close False
' Notify user
MsgBox "Data from MATERSHEET has been filled into the Word document!", vbInformation
' Clean up
Set wdDoc = Nothing
Set wdApp = Nothing
Set ws = Nothing
Set wb = Nothing
End Sub