I am using the following start to my VBA project, but when I run it I get a 1004 error and it highlights the below. The error seems to be the path, but I know not what the issue is.
Sub RentalFormstoWord()
'Declare variables for this automation
Dim wd As word.Application 'Word Application
Dim wdDOC As word.Document 'Word Document
Dim iRow As Long 'Variable to hold the starting row and loop through all records in the table
Dim sh As Worksheet 'Worksheet variable to refer the sheet where we have stored the table
'Start word and a new document
Set wd = New word.Application
'set worksheet where table is available
Set sh = ThisWorkbook.Sheets("Inventory Master Doc")
iRow = 2 'initialize iRow with 2 as our data is starting from row number 2 in table
Do While sh.Range("A" & iRow).Value <> ""
'opening the word template
Set wdDOC = wd.Documents.Open(ThisWorkbook.path & "Band_Rental_Agreement.dotx")
wd.Visible = False
I’ve tried naming the path “Band Rental Agreement.dotx” I’ve copied and pasted the doc title, I’ve used underscores instead of the spaces and I’ve copied the path itself.
New contributor
RavZerk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.