Subscript out of range Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Check your other post.
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.
 
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.
 

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

Back
Top