Sheet protection

kalim

Board Regular
Joined
Nov 17, 2010
Messages
87
Hi excel users.

I have a macro that I want to run with worksheet protection on. I am using the following code to enable macros to work with protection on. It works for cells but not a shapes text box I have. Any ideas on how to make this work for textBox 1 also?
Thanks.

Code:
Private Sub Workbook_Open()
 
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Protect Password:="password", _
UserInterFaceOnly:=True
Next wSheet
 
End Sub

Code:
Public Sub words()
 
ActiveSheet.Range("b2") = "sds"
    ActiveSheet.Shapes("TextBox 1").TextFrame.Value = "sds"
 
 
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
have you tried recording the macro and setting the values there, and see the results
 
Upvote 0
Thanks for the reply.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I have discovered that the above code works fine in excel 2010, but not in 2007. <o:p></o:p>
<o:p></o:p>
Any ideas on how to make the code compatible with 2007 also?<o:p></o:p>

The error I get in 2007 is 'unable to set the text property of the characters class"
<o:p></o:p>
Thanks.<o:p></o:p>
 
Upvote 0
kalim

In the properties of picture or textbox , check on "Locked and Text Lock".

and More

Code:
Private Sub Workbook_Open()
 
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Protect Password:="password", _
UserInterFaceOnly:=True, [COLOR=red]DrawingObjects:=True
[/COLOR]Next wSheet
 
End Sub
 
Upvote 0
Thanks for the reply.
I tried the added code and I still get the same error.

Any suggestions?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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