Run time error 1004: Method 'Sheets' of object'_Global' failed

Joined
Aug 11, 2011
Messages
1
Reaction score
0
I am having this error on an Excel report. I am running the code from an Excel form. The error only happens the first time I run the code each day. If I end the code and run it again, the report completes succesfully. The spreadsheet that I write to is an Excel template that has three worksheets. This error happens on the first iteration through a For Next loop as it tries to activate the first worksheet. I have an Excel object named XL1 and I have tried putting it in front of Sheets, but this did not fix the error. I tried setting the sheet to visible in a line before the error line and it gives the error on that line instead. Any help or suggestion would be welcomed.

Code snippet:
' Activate current worksheet.
Sheets(strWrkSheet(intCnt2)).Activate <--- ***Error happens here***
Set wks = ActiveSheet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top