I need to open a workbook from VBA without running the 'Workbook_Open' routine that is attached to it. I have seen a suggestion in this forum using a global variable but I can't seem to make it work...Any other suggestions?
I apologise for the global variable tip. I based it on a bug I had when I ran two spreadsheets side by side and the globals clashed. Now I can't get it to work.
You could use the application.username as a flag tho.
sub opener()
dim namehold as string
namehold = application.username
application.username = "No Macros"
'open the workbook
application.username = namehold
end sub
and in
sub workbook_open()
if application.username = "No Macros" then exit sub
If it crashes on the open event, you have lost the users username tho. There is probably an easier way but in the absence of that, this will work.
Other methods would be to get the opening files to check for the presence of the file that you use for opening and quit macros if it's there.
Following up on Acron's advice, I would also wrap the code to open the other workbook in some error trapping. If an untrapped error occurs, the subsequent
Code:
Application.EnableEvents = True
line will not execute. All event handling will then be deactivated.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.