VBA Add-in code not running on App_WorkbookOpen

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
I am missing something simple here. The code works fine until I put it into an add-in and open an excel.

Here are the steps:

(1) I create an application variable on Workbook_Open
(2) App_WorkbookOpen module calls three small pieces of code.
(3) Errors start such as "Object variable or With Block Variable" not set

The issue is that I have With statements such as:

With ActiveWorkbook
WinTag = .ProtectStructure Or .ProtectWindows
End With

I know the issue is in the ActiveWorkbook call.

Do I need to pass a workbook variable to the subs when I call them?

Thanks

Code:
Option Explicit


Dim WithEvents App As Application

Private Sub Workbook_Open()
    Set App = Application
End Sub


Private Sub App_WorkbookOpen(ByVal Wb As Workbook)


Call AllInternalPasswords


Call unhideAll


Call pasteValues




End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Solved.

I just passed the WB variable to the sub routines and and referred to the WB object.

Works fine now.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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