# Question with Formula

#### ryan_law2000

##### Well-known Member
Can anyone help with this...
How can I make these pictures import when the sheet is protected, I basically need it to bypass the protection.
this code works perfectly when the sheet is unlocked but once I protect it then the code does not work... I have even "unlocked" the cell the picture is being pasted in and still doesnt work
Any Ideas out there?

Code:
``````Private Sub CommandButton1_Click()
Dim myPicture As Variant
Range("C13").Select
myPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", _
, "Select Picture to Import")
If myPicture = False Then Exit Sub
Dim p    As Object
Dim Factor As Single
Set p = ActiveSheet.Pictures.Insert(myPicture)
'Width and Height are in points (1/72 inch)
Factor = 3.17 / (p.Width / 50)
p.Width = 230
p.Height = 173.5
End Sub``````

### Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

#### VoG

##### Legend
Try this, changing the sheet name and password as required

Code:
``````Private Sub CommandButton1_Click()
Dim myPicture As Variant
Sheets("Sheets1").Activate
Sheets("Sheet1").Range("C13").Select
myPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", _
, "Select Picture to Import")
If myPicture = False Then Exit Sub
Dim p    As Object
Dim Factor As Single
Set p = ActiveSheet.Pictures.Insert(myPicture)
'Width and Height are in points (1/72 inch)
Factor = 3.17 / (p.Width / 50)
p.Width = 230
p.Height = 173.5
End Sub``````

#### ryan_law2000

##### Well-known Member
Changed a few things and it works good now... One more question
When the picture is imported onto the sheet is there a way to import it as "Unlocked" so it could be deleted if needed with out unprotecting the sheet?

#### ryan_law2000

##### Well-known Member
Or...
When I import the picture can it be named "Picture1"
from there what I can do is create a remove button...

what formula would I use to name the picture "Picture1" automatically when imported into my sheet

and from there what formula would i use to remove"Picture1" from a command button?

#### Case_Germany

##### Active Member
Hi,

a name assign:

Code:
``````p.Width = 230
p.Height = 173.5
p.Name = "Picture1"``````
A name delete:

Code:
``````Sub Test()
ThisWorkbook.Worksheets("Sheet1").Shapes("Picture1").Delete
End Sub``````
Case_Germany

#### ryan_law2000

##### Well-known Member
PERFECT... Thanks so much!

Replies
9
Views
144
Replies
4
Views
286
Replies
6
Views
113
Replies
1
Views
1K
Replies
3
Views
188

1,191,548
Messages
5,987,215
Members
440,085
Latest member
MBecker79

### 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.

### Which adblocker are you using?

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

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