What is the difference between auto_open and workbook_open?

Title says it all....
thandelAsked:
Who is Participating?
 
Patrick MatthewsCommented:
Hi thandel,

Leo is correct.  I would just add that if you open a workbook with a Workbook_Open sub via code, you can keep
the event from firing with the line:

    Application.EnableEvents = False

right before you open it.  Be sure to turn events back on, though!

Regards,

Patrick
0
 
Leo EikelmanDirector, IT and Business DevelopmentCommented:
The most important difference is this:

auto_open will not run when the workbook is opened by a macro. workbook_open will run if the workbook is opened by a macro.

In the first case (Auto_Open), you can use Workbook.RunAutoMacros to run the macro after opening the workbook.

Cheers,

Leo
0
 
thandelAuthor Commented:
What happens if a workbook had both... which executes first?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Leo EikelmanDirector, IT and Business DevelopmentCommented:
workbook_open executes first
0
 
thandelAuthor Commented:
Can you think of any reason why it wouldn't excute at all provided the workbook contained both and macros security etc was set to run?
0
 
GrahamSkanRetiredCommented:
Both would execute. The main difference is that Microsoft want to disown the Auto_Open, so support for that is likely to disappear at some unspecified time.
0
 
Leo EikelmanDirector, IT and Business DevelopmentCommented:
hmm doesn't execute at all?

If Application.EnableEvents = True then Is the Sub Workbook_Open() in the code view behind the workbook object (it needs to be).

As far as I understood this event should always fire in these circumstances, bit if it still doesnt then you could alternatively use Sub Auto_Open() in any code module (this should
also work regardless of whether Excel has events disabled).

there may be something wrong with the document.  Would it be difficult to move everything to a new document?


Leo
0
 
thandelAuthor Commented:
I poke around and ensure I have all set correctly.  Your information gives me an understanding.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.