Workbook_open not firing due to compile error in class module (missing library reference)

Alex2302

New Member
Joined
Sep 24, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi all,
after days of (unsuccessful) research in the web and another forum I try my luck here.
Following problem: I try to add a reference (Outlook library) in the Private Sub Workbook_Open() event (yes, it's in ThisWorkbook) since I need early binding for getting Outlook events later in different places. Once I open my workbook I get a compile error "user-defined type not defined" in my class module here --> Private olApp As New Outlook.Application. I can understand this since the Outlook reference is not yet set and this is what I exactly try to do in the Workbook_Open event. This workbook is going to be used by multiple users. How does Excel work here? Does Excel first try to compile the COMPLETE project BEFORE it executes ANY code (e.g. in the Workbook_Open) event (enableEvents is set to True)?
Once I run the Sub Workbook_open manually, the reference is set without any problems.
Thanks in advance for any help/workaround. I can also accept an answer like: "Alex, you're screwed - there is no solution" ;)
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I found the problem :)
All buttons and checkboxes in the workbook were Form Controls and different macros were assigned to those controls. I found out that if I remove all macro assignments and reopen the workbook, the compile error disappeared and the reference was set successfully. I replaced all Form Controls by Active X Controls and everything works like a charm. Don't ask me why it didn't work with Form Controls. :unsure: I'm just glad that it's working now. :cool:
 
Upvote 0
Solution

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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