SteveO
SteveO

Reputation: 13

Workbook_Open sub won't run automatically when the workbook is opened

I need this macro to run when the .xlsm workbook is opened. It only runs if I manually run the macro, it does not start when the workbook is opened. FYI, I've checked/verified macro security (this is not signed yet).

Any ideas what I'm doing wrong?

Sub Workbook_Open()
MsgBox "Hello World!"
End Sub

Upvotes: 1

Views: 2607

Answers (1)

ashleedawg
ashleedawg

Reputation: 21619

Your code needs to be located in the ThisWorkbook module.

  1. Open the VBA Editor (Alt+F11)
  2. Open the Project Explorer (Ctrl+R)
  3. In the Project Explorer pane, double click ThisWorkbook. (If you have multiple workbooks open, make sure you choose the ThisWorkbook under the correct project.)
  4. In the code editor pane, click the drop-down that says General.

This will bring you to a new (or existing) Workbook_Open procedure:

Private Sub Workbook_Open()

End Sub

That's where your code should be placed.


Note that clicking the other drop-down at the top-right of the Code Editor pane, will list the other Workbook-level procedures you can add.


More Information:

Upvotes: 1

Related Questions