1

I want to run a macro every time an excel files opens and before it closes. I've tried using the below script but it didn't work.

Private Sub Worksheet_Activate()
'my macro
End Sub
3
  • 1
    How do you know it didn't work? Your script doesn't actually do anything.
    – DavidPostill
    Commented Oct 12, 2015 at 9:07
  • Put MsgBox("Hello World!") in, as David mentioned. Marked as "unclear what you're asking" Commented Oct 12, 2015 at 9:15
  • @DavidPostill I've written MsgBox("Hello World!") but nothing appears when I open the workbook
    – Tak
    Commented Oct 12, 2015 at 9:24

1 Answer 1

2

How do I run a macro every time a workbook opens or closes?

Opens:

Private Sub Workbook_Open()
' dosomething
End Sub 

or

  • Use Sub Auto_Open() in a module

Closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
' dosomething
End Sub 

or

  • Use Sub Auto_Close() in a module

Sources:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .