- If Program is the sheet name, enclose it in quotes:
Set xlSheet = xlBook.Worksheets("Program")
- Specify the sheet that Range belongs to:
Set rng = xlSheet.Range("A2:A50")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
I have a Macro on Word that in some part of the program it pulls information from an Excel File, the issue is that I used to get the error 1004 but not always, used to be at the second or third time that I run the Macro.
The Textbox48 is the file path which is correct because file always gets open.
"Program" if the sheet name which also is correct.
I call the workbook to be visible and sheet to be active as recommended prior to set rng.
Below is the portion of code where is pointed the error end some screenshots:
Pointing on "Set rng"
Pointing on "Dim rng"
Pointing on "Range"
The question still why this error is intermittent.
Hope you can help me.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Set xlSheet = xlBook.Worksheets("Program")
Set rng = xlSheet.Range("A2:A50")
Thank you for your help, it fix the problem.
Just to clarify, Program y a variable that contain the Sheet's name, so quotes aren't necessary.
> Just to clarify, Program y a variable that contain the Sheet's name, so quotes aren't necessary.
OK, that wasn't clear to me.