Protect And Hide Your Excel VBA Macros – Macro Mondays


Hello fellow Excellers, I hope you are well and thanks for joining me on another macro Monday blog post. I want to share with you today how to protect and or hide your Macros from prying eyes. There may be a number of reasons you want to hide your Excel VBA from users, just as you would want to hide some formulas from users of your Excel workbooks. Depending on the level of protection you want to implement, here is how to protect your VBA code and also hide your VBA code. A user is free to amend any Macros you have in an Excel workbook. I always protect my Excel Macros as a rule of thumb.

How To Protect Excel Macros and VBA

If you are happy for your users to see your Macros but not to be able to amend them in any way then your Password Protect them. Here is how to password protect your Macros

  • Open the workbook that contains your Macro
  • If the Developer Tab is not enabled, then enable it. You can find more information about the Developer Tab as well as enabling it in my blog post here.
  • Open the Tools Menu and then select VBA Project Properties
  • Select the Protection Tab
  • Click Lock Project for editing
  • Simply enter your chosen password twice
  • Finally hit Ok to finish up

Your project is now protected from any changes to it by users unless they know your password to unlock your file.

How To Hide Excel Macros and VBA

If you want to take security to another level and hide your macros from even being seen then you can hide them away.

  • Simply open the Macro that you want to hide from the users when they are in the workbook, and the Macro list is selected.
  • Find the first line of the Maro that you want to hide. After you have located the first line of the Macro enter “Private” in front of “Sub”.
  • This hides the Macro from the list of Macros saved in the Excel worksheet.

 

Let’s Work Through An Example Of How To Hide An Excel Macro.

I have a macro in my workbook called SayHello. You can see the code below.

It is easy to see the Macro when we hit the Macros option in the Developer Tab.

So, if we go back to our VBA code. All we need to do is type “Private” in front of “Sub”.

Let’s now see if the Macro is visible after this change. It looks like it has disappeared!. Your users won’t be able to see it either.

So, if you want to protect and hide your Excel macros from users of your workbook, you have two great options to choose from.

 


If you want to see all of my blog posts in the Macro Mondays Series you can find them all at the link below. Why not bookmark it?, Yes, it is updated EVERY Monday.

How To Excel At Excel – Macro Mondays Blog Posts.

If you want more Excel and VBA tips then sign up for my monthly Newsletter where I share 3 Tips on the first Wednesday of the month and receive my free Ebook, 30 Excel Tips.

excel tips to help you excel at excel

 

 

 

 

Next Steps?. Do You Want To Learn How Write Excel Macros? Check Out Chandoo’s VBA Classes.

vba-classes-logo

 

Barbara

Barbara is an experienced data analyst with over 20 years of experience. Author of the How To Excel At Excel Top 50 Excel tips Ebook, YouTuber and Excel Blogger.

Recent Posts