PDA

View Full Version : Problem showing images in locked sheet



paulxl
07-05-2011, 06:31 AM
I have a spreadsheet that displays an image for a result using this event macro I found on McGimpsey & Associates website:

Private Sub Worksheet_Calculate()
Dim oPic As Picture
Me.Pictures.Visible = False
With Range("b11")
For Each oPic In Me.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
Exit For
End If
Next oPic
End With
End Sub

This works great unless I protect the worksheet and then I get the following error message:

"Run time error '1004':

unable to set the Top property of the Picture class"

I suspect there would be a problem with the Left property too, if it ever got that far.

I need to protect the sheet because I want to let others (with no excel capabilities) use the sheet without modifying it

Kenneth Hobs
07-05-2011, 08:36 AM
Welcome to the forum. What is the Me object?

You can of course unprotect and protect a sheet but that should not be needed. I suspect that you need the activesheet object rather than Me.
Private Sub Worksheet_Calculate()
Dim oPic As Picture
ActiveSheet.Unprotect "ken"
ActiveSheet.Pictures.Visible = False
With Range("B11")
For Each oPic In ActiveSheet.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
Exit For
End If
Next oPic
End With
ActiveSheet.Protect "ken"
End Sub

paulxl
07-05-2011, 11:15 AM
Thank you. I've spent so much time on this a simple solution was never going to occur to me!