Run VBA Macros When A Spreadsheet Opens or Closes
Run VBA Macros When A Spreadsheet Opens or Closes
In this post we will focus on the Open and BeforeClose events. The image below shows how you can navigate to
the Workbook Object within the Visual Basic Editor. The Workbook Object is where workbook events can be
accessed through VBA code.
The below code displays a message box to the user when the workbook is opened and right before the workbook
closes. Environ("Username") retrieves the user's computer login name.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
End Sub
Private Sub Workbook_Open()
End Sub
The following code runs a macro called AddTodaysDate when the workbook is opened.
Private Sub Workbook_Open()
Call AddTodaysDate
End Sub
I highly recommend that you check this guide out before asking me or anyone else in the comments section to
solve your specific problem. I can guarantee 9 times out of 10, one of my strategies will get you the answer(s)
you are needing faster than it will take me to get back to you with a possible solution. I try my best to help
everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite
enough hours in the day!).