Macro On Open

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What code do I need to run a macro when a file is opened? The sub name is
PNL. Also, this file is password protected. Will that affect anything?

Thanks

Adam Bush
 
All+F11 to enter VB editor. Double-click ThisWorkbook.

Paste the following:

Private Sub Workbook_Open()
<Your Code Here>
End Sub


I believe the code will run once the password is entered.
Regards,
Paul
"(e-mail address removed)"
 
You could rename that sub to Auto_Open.

As long as it's in a General module (and there isn't an existing sub named
Auto_Open), it should run.

(and if the user allows macros to run)

And if the user can open the workbook, I would bet that the password protection
won't bother the macro. But you'll know for sure when you test it.
 
You should put an Auto_Open macro in a separate module.
Make sure the name is Auto_Open.
In there, you call your PNL-macro.

Public Sub Auto_Open()
Call PNL
End Sub

Private Sub PNL()
MsgBox "This File is password protected"
End Sub

As soon the protection-password is entered, the macro will run.




"(e-mail address removed)"
 
Thanks a lot Paul worked perfectly!

PCLIVE said:
All+F11 to enter VB editor. Double-click ThisWorkbook.

Paste the following:

Private Sub Workbook_Open()
<Your Code Here>
End Sub


I believe the code will run once the password is entered.
Regards,
Paul
"(e-mail address removed)"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top