Blocking access to VBA code

stubarny

New Member
Joined
Apr 7, 2011
Messages
41
Hello,

Please could someone tell me how to block access to view the raw VBA code (e.g. incase a user presses Alt-F11, or tries to edit a macro)?

Many thanks,

Stu
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Tools > VBA Project Properties > Protection tab, tick Lock Project for Viewing and enter a password. Save, close and re-open to see the effect.
 
Upvote 0
This is not working. I am currently running Excel 2007. I go into view code --> tools --> VBA project properties --> protection tab and then I check the box and enter the password. I save, recheck it before closing and see that the password is still there and the box is ticked. After closing and reopening, I can go into my code and the protection tab is then blank. I've tried right clicking the module, but no luck. Any advice on what could be wrong?
 
Upvote 0
Hi Vog,

Many thanks :-)

Please could you tell me if it's possible to lock the VBA by using VBA code rather than going through the menus? I tried to use the macro record button but it didn't record anything that I did within the VBA window.

Thanks,

Stu
 
Upvote 0
No, I'm pretty sure you can't do that. If you could you could do the reverse which would defeat the object of protection.
 
Upvote 0
Thanks VoG.

(the reason that I was asking is that I have a macro file which populates a template report file - I'd like to leave the VBA unprotected in the template report file so that when I work on the VBA code I don't have to keep entering the password (which I currently have to do). Then when a new report is created using the template report file I'd like that new file to have the VBA protected).
 
Upvote 0
First, make a macro using SendKeys() to do it. Then play it from your personal workbook. Make another to protect it.

Another way to play the macros would be, put these into the workbooks Open and Close events. Put an IF to check for something unique. e.g.
Code:
If Environ("username") = "Ken" then ...
You could even use the Application.Run to run the personal workbook protect and unprotect macros just in case someone hacks your If() routine.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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