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
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
Solved.

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

Works fine now.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,519
Messages
5,596,634
Members
414,082
Latest member
sasmita

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
Top