"Cannot use this command on a protected sheet"

HELP!

I have a bit of code that runs under a button but produces an error once the Excel worksheet is protected. I need to protect most of the elements on the sheet once published, but would like to retain the functionality of the button code.

The code allows a user to select and insert a picture into a cell on the worksheet. The code is as follows...

Private Sub CommandButton1_Click()
Range("A6").Select
Dim PicLocation As String
PicLocation = Application.GetSaveAsFilename("C:\Windows\My Documents", "Image Files (*.jpg),*.jpg", , "Specify Image Location")
If PicLocation <> "" Then
ActiveSheet.Pictures.Insert(PicLocation).Select
Else
Exit Sub
End If
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Width = 235#
Selection.ShapeRange.Height = 165#
With Selection
.Placement = xlMoveAndSize
.PrintObject = True
End With
Range("D17").Select
End Sub

Is there a way to achieve the same effectandprotect the locked cells of the sheet?

[1256 byte] By [suznal] at [2008-1-9]
# 1

Code Snippet

Private Sub CommandButton1_Click()

' before

ActiveSheet.Unprotect

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' after

ActiveSheet.Protect


End Sub

bi-lya at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2

Provided the result I was after.

Thank you!

suznal at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...