VBA Code in Workbook_Open Prevents Double Clicked Excel Workbooks from Opening at Startup

bissettbd

New Member
Joined
Aug 2, 2010
Messages
6
I have some code I placed in the Sub Workbook_Open in an xlsm file which is placed in XLSTART folder.
The code executes properly when Excel is opened.

Problem. If any code is in the Sub Workbook_Open, and the user double clicks an Excel Workbook and Excel is CLOSED, the workbook will open, the VBA Code will Execute, but the Doubleclicked Excel File WILL NOT OPEN in Excel when it starts. Remove code in Sub Workbook_Open and double clicked files will open normally. If Excel is already OPEN, the code in Sub Workbook_Open has no effect, double clicked files will open right up in Excel.

Has anyone else noticed this behavior? :eek: I have tried Sleep and DoEvents in the Sub Workbook_Open to try and allow the doubleclicked file time to open at startup before the VBA Code begins to Execute but this did not work.
Any ideas?
Thanks.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I have tested this theory with a new Excel Macro file in 'XLStart' (I just have a helloworld dialog on start)

The Code runs when Excel Starts, It also runs when a file is opened (double clicked) when Excel is not running. All files still open with this code installed.

However It is possible to run code in the open event that may interrupt, opening a document.

Could you post your code so that we can identify any issues?
 
Upvote 0
The code in question was reading an XML Document via http.
httpQueryString = "http://coreivfdev.sspf.xxx.xxx/services/IVFCoreService?PIN=" & GetUserPin & "&Application=Test"
If XMLDoc.Load(httpQueryString) Then

This would hang Excel and not permit a double clicked document to Load.
I found this workaround using Application.OnTime to provide a few seconds for any double clicked documents to open.
Interesting that neither sleep nor DoEvents would allow a double clicked workbook to open during their Idle period. Neither works as advertised.

Private Sub Workbook_Open()
'Populate the XML fields
'Use Application.OnTime to give Excel 5 Seconds to Open any Double Clicked Files at Startup
Application.OnTime Now + TimeValue("00:00:05"), "PopulateOfficeXMLTags"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top