I am opening a workbook via VBA that has the Workbook_Open event in it. How do you bypass the Workbook_Open Even in code.
Printable View
I am opening a workbook via VBA that has the Workbook_Open event in it. How do you bypass the Workbook_Open Even in code.
I'm not sure you can.. you can open a workbook that has a module with Auto_Open in it.. but it will run the Workbook_Open code regardless..
There is no parameter to prevent this.. If it is your own workbook then I suggest you change it to Auto_Open in a module instead..
Sopunds like you are opening this workbook from within another workbooks vba code. So not too much you can do. If its in your primary workbook you can do this.
VB Code:
Private Sub Workbook_Open() 'Bypass Exit Sub 'Other open code 'Blah, blah, blah End Sub
Not meaning to re-start the fight but the Auto_open procedure inside a module will not run unless you specify to run it..
for example
VB Code:
Sub WorkBook_Open() Msgbox "Workbook open event performed." End Sub 'in a module (Not ThisWorkbook or behind any sheets) Sub Auto_Open() Msgbox "Auto open procedure performed." End Sub
Save that into a workbook and then from a second workbook simply do
VB Code:
Workbooks.Open("C:\MyWorkbook.xls")
And see which msgbox appears.. you should only get the workbook event.. if however you follow your workbook open code with the following
VB Code:
ActiveWorkbook.RunAutoMacros xlAutoOpen
Then you should see both messages..
The Auto_Open method does not fire unless coded specifically, whereas the Workbook_Open will fire regardless.. (Unless of course you have the security set to high)
Right, but if the second workbook can not be modified then that workbooks Open event will fire. :(
Correct and if it is locked then there is nothing you can do to change it, apart from set the security higher.. :)
Instead of going through all this, what is the reason you need to bypass the open event for it? Maybe there is another way to look at this?
I need to bypass Workbook_open Event because what I am doing is I have an Excel workbook that in code opens up other Excel files and parses the data. One of the files has the Workbook_open Event to add a command bar that references an Addin I don't have access to. So my Automation fails.
Is the file locked down or can you access the VBA behind it.. If so change it to the Auto_Open in a module instead.. It will still fire when the workbook is opened normally
If that was the case wouldnt that have been done before a thread was posted?
How about copying the file, making it writeable, change the vba code and be done with it?
Everyday I receive numerious Excel Files with different data everyday from different sources. The source that sends the file will not remove the code or module. I am trying to complety automating parsing the data. Setting the security to High actually doesn't work in this instance.
Setting the security to high will probably prevent your code from working..