VBS GetObject will not bind to saved workbooks

0

I'm trying to write a script which will switch to a specific excel workbook and enter keys, however, the script will only run if the workbook which is being referenced is unsaved.

For example:

If I open a new excel workbook which creates a new workbook named "Book1"; the following works:

Set xl = GetObject("Book1").Application

If I run the above when the workbook has been saved, even if the name remains the same, the above results in the following error: (0x800401E4).

Is anyone aware of this being a problem, or can anyone point out what I'm doing wrong? I'd guess the error has something to do with the object name being different from the actual file name, so when excel creates the default workbook the code works because the name of the instance is "Book1" whereas the saved "Book1" is assigned another object name when saved?

vba
excel
vbscript
asked on Stack Overflow Oct 19, 2016 by Nulled

1 Answer

0

I wasn't sure if I needed to close this question as answered, however, it seems that https://stackoverflow.com/users/4088852/comintern has resolved the issue.

It needs to be the full path - GetObject("C:\Users\Me\Documents\Book1.xlsm").

Thanks,

answered on Stack Overflow Oct 19, 2016 by Nulled • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0