Workbook_Open Event Runs Too Soon

Billy Hill

Board Regular
Joined
Dec 21, 2010
Messages
73
I get a daily report emailed to me in Excel format. It's hidious to read so I made a macro to clean it up so I can run it when I opent he workbook.

There is only one sheet, named LockedSupplierReport, and I'd like to use the Workbook_Open event to test for this sheet name and run the macro automagically when it opens.

If I run the two lines in the debug window while the report is opened it works. But when I put the code in ThisWorkbook in the Workbook_Open function it seems to run before the report opens.

Code:
Private Sub Workbook_Open()
s = Sheets(1).Name
If s = "LockedSupplierReport" Then Call LockedSupplierReport
End Sub

To test this I changed the code to this, saved and closed excel, then re-opened the report.

Code:
Private Sub Workbook_Open()
s = Sheets(1).Name
MsgBox s
If s = "LockedSupplierReport" Then Call LockedSupplierReport
MsgBox "Didn't work, did it?"
End Sub

When I open it, Excel opens and pops the msg box up with "Sheet1" then "Didn't work", then it opens the report.

How can I get this code to run after the report is open?
 
Thanks Rory. I did a little research and, understandably so, all that selecting is slowing down my spreadsheet.

Thanks for the heads up.
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top