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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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