VBA to Lock all Cells in all Worksheets

tomexcel1

New Member
Joined
Feb 22, 2018
Messages
47
Hi All

I have an excel workbook with around 6 worksheets, when the final user presses a button I want all the cells in every workbook to be formatted to "Locked" and then every worksheet locked with a password.

Basically once the final user signs it off the workbook can no longer be edited.

Is there a quick way of doing this?

Thanks All

Tom
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Maybe something like
Code:
Sub tomexcel1()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      Ws.Cells.Locked = True
      Ws.Protect "Pword"
   Next Ws
End Sub
 
Upvote 0
That works perfect thank you! 1 final question is it possible to set all active active x command buttons to inactive or hidden on all sheets??

Thanks
Tom
 
Upvote 0
How about
Code:
Sub tomexcel1()
   Dim Ws As Worksheet
   Dim Obj As OLEObject
   
   For Each Ws In Worksheets
      For Each Obj In Ws.OLEObjects
         Obj.Enabled = False
      Next Obj
      Ws.Cells.Locked = True
      Ws.Protect "Pword"
   Next Ws
End Sub
This will disable all objects, not just command buttons.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
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