running macros in locked sheets

Warwick T

New Member
Joined
Jan 25, 2019
Messages
2
Hi all,
I received help on this problem for a previous project from this forum, for which I was very grateful.
The code I was given is as follows:


Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In Sheets
ws.Protect Password:="dataplan", UserInterFaceOnly:=True
Next ws
End Sub


this worked perfectly in the original project

I then tried to use the same coding in another project to do exactly the same thing.

It runs most of the code ok but baulks at hiding rows and columns - while it had the same function in the first project. An example is below - the third and fourth last rows (both starting .range) are where the debugger finds a problem.


Sub Tab_Term1()
With Sheet1
.Shapes("Term1On").Visible = msoCTrue
.Shapes("Term1Off").Visible = msoFalse
.Shapes("Term2On").Visible = msoFalse
.Shapes("Term2Off").Visible = msoCTrue
.Shapes("Term3On").Visible = msoFalse
.Shapes("Term3Off").Visible = msoCTrue
.Shapes("Term4On").Visible = msoFalse
.Shapes("Term4Off").Visible = msoCTrue
.Range("A:W").EntireColumn.Hidden = False
.Range("X:DZ").EntireColumn.Hidden = True
End With
End Sub




Any suggestions / solutions gratefully received.

regards

Warwick
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi there. Modify your protect line like:
Code:
ws.Protect Password:="dataplan", UserInterFaceOnly:=True[COLOR=#ff0000], AllowFormattingColumns:=True[/COLOR]
(change in red)
 
Upvote 0
Glad I could help and thanks for the feedback. I can't think why it worked before!
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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