Run Macro After Opening a specific Workbook

  • Context: I have a spreadsheet tied to a bloomberg terminal. The spreadsheet in it has Bloomberg formulas which update after 1-2 seconds of being opened.


    Problem: I have set an event in windows task manager to automatically open the workbook at a given time each day (say, 4:30PM). At that point, the spreadsheet will update automatically. 5 seconds later, I want it to run a macro (which I've tested and works fine) automatically. I have been able to do this using the code below, but the problem is that it runs this macro every time a workbook is opened. I only want it to run when the specific workbook in which it's contained is open. I'm positive this has a simple answer, but have searched around and can't find anything.


  • Re: Run Macro After Opening a specific Workbook


    Are you saying your macro runs every time a new workbook is open, no matter if it's the workbook that contains the macro, or not?


    If so, try testing if the name of the ActiveWorkbook (the one that's been just opened) is the same as the name of ThisWorkbook (the workbook that contains the macro.


    I'm thinking something along the lines of


    Code
    If ActiveWorkbook.Name = ThisWorkbook.Name Then
    'Run macro
    Else
    Exit Sub
    End If
  • Re: Run Macro After Opening a specific Workbook



    That worked perfectly. So simple so easy. Thanks!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!