Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 9: Subscript Out of Range Dilemma

Status
Not open for further replies.

Rob94

Programmer
Mar 30, 2004
19
US
Here is my dilemma. The following code snippet listed below depicts an object variable name "xlobject" that holds an instance of "Excel.Application". At this point in the code, I have one workbook assigned to the "xlobject" (meaning that xlobject.workbooks.count = 1). The first line of code is supposed to add an existing workbook to "xlobject", bringing the workbook count of "xlobject" up to 2. The last line is supposed to set the "xlMasterWorkbook" object to the 2nd workbook. When I step through this code in debug mode, it works fine, but when I let it run normally from the browser, it bombs out on the last line with a "Subscript Out of Range" error. Is it that the code is executing too fast to set the "xlMasterWorkbook " when run in the browser? BTW...when I run this in debug mode, the message box reports a value of "2". When I run this normally in the browser, the message box reports a value of "1". I'm pretty sure this is why I'm getting the "Subscript Out of Range" error, but my question is how can I resolve this? Any help is greatly appreciated.

Code:
'open master workbook	
xlobject.workbooks.open CS_sSpreadsheetPath &  sMasterWorkbookFileName
MsgBox "Workbook count:" & xlobject.workbooks.count
set xlMasterWorkbook = xlobject.workbooks(2)

Thanks - Rob94
 
Have you tried this ?
'open master workbook
set xlMasterWorkbook = xlobject.workbooks.open(CS_sSpreadsheetPath & sMasterWorkbookFileName)
MsgBox "Workbook count:" & xlobject.workbooks.count

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
phv,

the workbook count is still 1....

:(

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top