ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Subscript out of range Error (https://www.excelbanter.com/excel-programming/399328-subscript-out-range-error.html)

CH

Subscript out of range Error
 
I have a VBA that is :

set WH = workbook("file1"). file1 is an open excel workbook.

It works fine mostly but on 1 of my colleagues' PC, it gives "subscription
out of range".

We were told to change the line to :
set WH = workbook("file1.xls") with the xls extension and it now works fine.

How can we get VBA to accept both file1 and file1.xls as valid input?

Thanks.

Dave Peterson

Subscript out of range Error
 
Check your other post.

ch wrote:

I have a VBA that is :

set WH = workbook("file1"). file1 is an open excel workbook.

It works fine mostly but on 1 of my colleagues' PC, it gives "subscription
out of range".

We were told to change the line to :
set WH = workbook("file1.xls") with the xls extension and it now works fine.

How can we get VBA to accept both file1 and file1.xls as valid input?

Thanks.


--

Dave Peterson

JLGWhiz

Subscript out of range Error
 
When you are defining the object variable with the Set method, you must use
the three digit (four with xl2007) file extension code preceded by a period
[.] . This is because Excel files can have several different file extension
codes for the same basic name. You have charts, templates, macro sheets,
etc. that can all have the same basic name as the .xls file.

"ch" wrote:

I have a VBA that is :

set WH = workbook("file1"). file1 is an open excel workbook.

It works fine mostly but on 1 of my colleagues' PC, it gives "subscription
out of range".

We were told to change the line to :
set WH = workbook("file1.xls") with the xls extension and it now works fine.

How can we get VBA to accept both file1 and file1.xls as valid input?

Thanks.



All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com