Prevent Workbook_Open macro from running on opening

KitaYama

New Member
Joined
May 18, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
When I used to work with Excel (2 decades ago), I was able to press shift and click an Excel file to prevent running the code in Workbook_Open sub.

But it seems it doesn't work anymore.
I've tried shift+double clicking the icon
And
Launching Excel, going to File in ribbon and Open tab, then shift+clicking the file name in the list.

In any case the code is executed.
I have to change trust settings anytime I need to edit the sub.

How can I open an Excel book and prevent the code in Workbook_Open sub being executed?

Office 365
Windows 11

Thanks.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
sounds daft but have you tried holding the shift continuously until the file has finished loading rather than when you just click open?
 
Upvote 0
Nope, that feature has been removed from Excel, unfortunately. A workaround is to include a test for the presence of a small txt file in the same folder as the Excel file. Something like this (untested):
VBA Code:
Private Sub Workbook_Open()
    If Len(Dir(ThisWorkbook.Path & Application.Pathseparator & "NoWorkbookOpen.txt"))> 0 Then Exit Sub
'Rest of code
 
Upvote 0
Solution
Nope, that feature has been removed from Excel, unfortunately. A workaround is to include a test for the presence of a small txt file in the same folder as the Excel file. Something like this (untested):
VBA Code:
Private Sub Workbook_Open()
    If Len(Dir(ThisWorkbook.Path & Application.Pathseparator & "NoWorkbookOpen.txt"))> 0 Then Exit Sub
'Rest of code
Thanks. I think I can do that.
 
Upvote 0
A workaround is to include a test for the presence of a small txt file in the same folder as the Excel file.
Hi Jan Karel. So if you received a workbook from somebody else and were concerned about possible Workbook_Open code would the only option be to ensure that you had
- macros disabled, and
- the workbook not in a trusted location?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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