worksheets with VBA - protection

Robert_G

New Member
Joined
Jul 13, 2018
Messages
48
Can worksheets be protected to view only that have VBA code assigned to them that are linked to other worksheets?

I have one work sheet that is for data entry and another work sheet link that I want to be viewed only. The view only worksheet has cell's linked to the first with charts, conditional formatting and VBA assigned in specific parts.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
After you have protected and unprotected the cells properly as you do for manually protecting the sheets, you can use the code below to protect it from users but not from macro (the macros will run as if it was not protected).
Code:
[LEFT][COLOR=#222222][FONT=monospace]
[/FONT][/COLOR]        Activesheet.Protect Password:=[FONT=monospace]"abc"[/FONT], UserInterfaceOnly:=[FONT=monospace]True[/FONT][COLOR=#222222][FONT=monospace]
[/FONT][/COLOR][/LEFT]

It is much easier to automatically protect all the sheets when opening the file, so you can unprotect them to work on the file and forget about protecting them when you are done..

In VBA, you have the sheets in left column. 2x click on "This Workbook" and paste this code to do so.
Code:
[LEFT][FONT=Courier New][LEFT][FONT=Courier New][LEFT][FONT=monospace]Private[/FONT] [FONT=monospace]Sub[/FONT] Workbook_Open()
    [FONT=monospace]Dim[/FONT] wks [FONT=monospace]As[/FONT] Worksheet
    [FONT=monospace]For[/FONT] [FONT=monospace]Each[/FONT] wks [FONT=monospace]In[/FONT] ThisWorkbook.Worksheets
        wks.Protect Password:=[FONT=monospace]"abc"[/FONT], UserInterfaceOnly:=[FONT=monospace]True[/FONT]
    [FONT=monospace]Next[/FONT] wks
[FONT=monospace]End[/FONT] [FONT=monospace]Sub[/FONT][/LEFT]
[/FONT][/LEFT]
[/FONT][COLOR=#ffffff][FONT=Courier New]
[/FONT][/COLOR][/LEFT]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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