Protecting a Workbook for Macro Only Changes

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I have a workbook that displays lots of data over several sheets. The workbook is designed so that there is a macro and/or user form for all functions, data entry, and data manipulation. Plain and simple, I don't need or want the user to be able to click anywhere in the workbook except for the command buttons I've placed along the top of the page (in row 1) that run the macros.

While I've never learned how to use VBA to protect, run macro, and then re-protect, this is the first method that comes to mind, and I'm willing to learn how to do it. My biggest fear with this, is how cumbersome it will be to find every spot in this complex program where a macro needs the ability to manipulate data on a worksheet where protection needs to be cleared first, then re-protected.

Is there a better way to do this? The user just needs to have authority to click the command buttons, and enter text/select option buttons or combo boxes within the user forms that pop up. The macros will always need the ability to add/modify data, and sort. If possible, I don't even want the user to be able to hide/unhide or resize rows or columns without using my macros to do it. And lastly, if there's a good way to secure the macro code from mischievous coworkers who think they know how to code, that'd be excellent too.

This is my first major project and it has been months of coding thousands of lines. I don't know much about protecting sheets, and I don't want to learn the wrong way first. Thanks!
 

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.
Have a look at the Worksheet.Protect Method in Excel Help. In particular, this method has an optional argument: UserInterfaceOnly which if set to True will allow the sheet to be protected against user changes while allowing your macros to make changes.

To implement this you would put a line at the start of a macro which looks like:
Code:
Sheets("Sheet1").Protect Password:="Your password between the quotes", UserInterFaceOnly:= True

EDIT: Forgot to mention that your macros can also be password protected against user tampering. In the VBE window go to Tools>VBA Project Properties>Protection tab to set the password.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,272
Members
448,558
Latest member
aivin

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