Forum Discussion

connderosa's avatar
connderosa
Copper Contributor
Sep 13, 2022
Solved

Automatically run a macro when opening a workbook

I can't seem to figure this out, and now I'm afraid I may have done the dreaded:   "Important: VBA code cannot be undone, so make sure to test your code on a blank workbook, or a copy of an existin...
  • mtarler's avatar
    Sep 13, 2022

    connderosa you need to open the VBA window (ALT-F11) and then in the project explorer (CTRL-R if it isn't already open) you expand the 'microsoft excel objects' folder and double click the "ThisWorkbook".

    You should then get a blank page as shown in the image below and click the left drop down and select 'Workbook'.  This should automatically insert a 

    Private Sub Workbook_Open()

    End Sub

    Then put the code you want to run between those 2 lines

    and in the end make sure you save it as a .xlsm or .xlsb file type

     

    hmmm... I should have opened that link first as it says the same thing but better. lol.

    so maybe you need to explain better what your question/need is

Resources