Question with Formula

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try this, changing the sheet name and password as required

Code:
Private Sub CommandButton1_Click()
   Dim myPicture As Variant
   Sheets("Sheets1").Unprotect Password:="xyz"
   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
   Sheets("Sheet1").Protect Password:="xyz"
   End Sub
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,974
Members
448,934
Latest member
audette89

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