Insert object into protected sheet

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I have a macro that inserts a picture into a worksheet. It's working perfectly in Excel 2007. The worksheet is protected, but the cells where I want to put the picture are unlocked. In 2007 it just puts them where instructed. In 2003 I get a Run-Time error 1004 "Cannot use this command on a protected sheet". When I protected the worksheet I selected the option that users can select unlocked cells and can edit objects. I'm stumped here. I need the users to be able to insert a picture, and delete it if the had selected the wrong one. Can anyone see a way around this? thanks in advance. The code is here:
Code:
Sub Insert_Picture()
 
Dim myPicture As Variant
Dim myCell As Range
 
    myPicture = Application.GetOpenFilename _
        ("Pictures (*.gif; *.jpg; *.bmp; *.tif; *.png),*.gif; *.jpg; *.bmp; *.tif *.png", , "Select Picture to Import")
    If VarType(myPicture) = vbBoolean Then
        MsgBox "Operation Cancelled"
    Else
        With ActiveSheet
            Set myCell = .Range("B5:O30")
            .Pictures.Insert(myPicture).Select
 
                With myCell
                    Selection.Top = .Top
                    Selection.Left = .Left
                    Selection.Width = .Width
                    Selection.Height = .Height
                    Selection.Placement = xlMoveAndSize ' move and size with cells
                    Selection.PrintObject = True
                    '.Select
                    End With
 
        End With
    End If
    Range("B4").Select
 
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,216,172
Messages
6,129,290
Members
449,498
Latest member
Lee_ray

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