Prevent opening a worksheet if macro are not enabled

Gringoire

Board Regular
Joined
Nov 18, 2016
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hello guys,
I createdan Excel file where some Sheet is protected/filled/formatted by VBA code.
This is to prevent the user to introduce inconsistent data, modify layout, etc...

Everything works fine if the user accept the standard application request to enable the macro in the workbook.
If the user refuses to enable the macro, the Sheets are still shown but macro are not executed and some sensible data, formatting, etc remains totally unprotected.

How can I prevent someone to open the excel file (or at least the Sheets with sensible data) if he refuses to enable the macro? I haven't found any tip on the internet...

thank you.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Its kind of a Catch-22 type of situation - in order to do something like that, it would require VBA code. But if they disable VBA code, it won't work!

The way I have seen people approach something like this is to have VBA code that runs on the "Before Close" event that hides and protects all sheets.
Then, have VBA code in the "Open" event that will unprotect and unhide all the sheets.
That way, if they try opening the file without enabling macros, they will basically open a workbook where they cannot see or do anything.
 
Upvote 0
Solution
Nice idea and very simple as soon as it keep in mind...
I totally missed this possibility!

Thank you for the suggestion.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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