Code not running when workbook opened

h4a4r6r6

New Member
Joined
Aug 21, 2018
Messages
5
Hi,


As per the title, the below code is not executing when I open the workbook. Sometimes it executes as intended and other times it doesn't. Can anyone suggest a reason why and offer a solution please. The workbook has password protection and is used by other people in my workplace so for them is opened read only.

Code:
[/COLOR]Option ExplicitPrivate Sub Workbook_Open()


    'Maximise the window when the workbook is opened
    Application.WindowState = xlMaximized


    'Show the navigation bar
    Call show_navigation


    'Activate worksheet
    AppActivate ThisWorkbook.Application



End Sub[COLOR=#333333]

Thank you.
 
Tried the above and still the same unfortunately.
What exactly happened?
Did it at least return the Message Box?
If it did not, it is not a problem with that code. The problem is that the code is never being called.
The only ways that I know of where that can happen is the following:
1. Your code is in the wrong place (it is not in the "ThisWorkbook" module of the workbook you are opening)
2. Your code has the wrong name (i.e. you edited the first line that says "Private Sub Workbook_Open()")
3. Macros/VBA code is not enabled
4. Events are not enabled

I cannot think of anything else that would prevent your code from running. It is almost certainly one of those things. The question is which one?

If you open it up, and are not even getting the Message Box pop-up, with that workbook open, go into the VB Editor, add those code to the workbook, manually run it and see what it returns:
Code:
Sub AreEventsEnabled()
    MsgBox "It is " & Application.EnableEvents & " that events are enabled."
End Sub
That should either confirm or rule out the 4th option.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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