Showing images in a locked spreadsheet

paulxl

New Member
Joined
Jul 5, 2011
Messages
4
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>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code:
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
Me.unprotect "Password"
oPic.Top = .Top
Pic.Left = .Left
ooPic.Visible = True
Me.protect "Password"
Exit For
End If
Next oPic
End With
End Sub

Omit the password bit if your sheet's not password protected, and replace the text "password" with the real password, if it is. Also, if you do need to put the password in, best to protect your project from viewing as well, otherwise others could see the hard-coded password in your project.
 
Upvote 0
Oh, and welcome to Mr Excel!
Sorry - didn't notice it was your first post here.
 
Upvote 0
Pleasure. Glad it worked for you, and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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