Workbook_Open not executing from Personal workbook

macfuller

Active Member
Joined
Apr 30, 2014
Messages
319
Office Version
  1. 365
Platform
  1. Windows
Excel 2013 64-bit

I have procedures to add right-click menu options that I want to call whenever a workbook is open. The code is in the ThisWorkbook portion of personal.xlsb.

Private Sub Workbook_Open()
AddShortCuts
AddNewVBEControls
End Sub

However, the code is not executing when i open either existing or new spreadsheets. Enable all macros and trust the VBA model are set in Options.

For security reasons I can't send .xlam files to various users so I can't embed macros in the spreadsheets themselves. I don't know if my IT department set an obscure policy flag since this used to work reliably.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Option Explicit

Dim WithEvents app As Application

Private Sub Workbook_Open()
  Set app = Excel.Application
End Sub

Private Sub app_WorkbookOpen(ByVal Wb As Workbook)
  AddShortCuts
AddNewVBEControls
End Sub
 
Upvote 0
Thank you. I'd seen that in another thread and tried it with failure. It turns out I needed to shut down Excel and restart for the new code to work.

I also have a close event to clear the controls from the menus. I'll assume that also has to be fired by the App event. Should I also set App = nothing in the close event?
 
Upvote 0
It turns out I needed to shut down Excel and restart for the new code to work.
That's one way, or you could have just executed the Workbook_Open event.

I also have a close event to clear the controls from the menus.
In app_WorkbookClose

I also set App = nothing in the close event?
Not if you want the code to run the next time you open a workbook.
 
Upvote 0
If I close all my workbooks and open a new one, the App_WorkbookOpen does not fire. If however I close all workbooks and open an existing file the code does fire. Since the added menu options are removed when I close all workbooks is there a way to fire the event for a new workbook so my menu options come back?
 
Upvote 0
When I start Excel both NewWorkbook and Workbook_Open are firing giving me duplicate menu items. Not a big deal, but what sort of test can I run to block one of them? Interesting Workbook_Open is triggered for a new sheet when opening Excel but not when opening a new sheet when Excel is already active!
 
Upvote 0
Create a static variable to contain a workbook name.

In the Open event, set the variable to the workbook name. In the other event, check to see if the name is the same as the one you already processed.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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