I want to insert a picture in an unlocked cell of a protected shee

D

DiamondDave44

I want to insert a picture in an unlocked cell of a protected sheet. How do
I do that?
 
B

BoniM

You can't. Pictures don't go in cells, they are objects over the sheet and a
protected sheet, by default, does not allow the addition of objects.
 
G

Greg Wilson

Try something like this:

Const FileTypes As String = "Picture files (*.bmp; *.gif; *.tif; " & _
"*.jpg; *.jpeg), *.bmp; *.gif; *.tif; *.jpg; *.jpeg"

Sub InsertPict()
Dim ws As Worksheet
Dim P As Picture
Dim c As Range
Dim h As Single, r As Single
Dim PNm As Variant

Set ws = ActiveSheet 'Sheets("Pictures")
ws.Unprotect
Set c = ws.Range("B2")
With Application
PNm = .GetOpenFilename(FileTypes, Title:="Select Photo")
If VarType(PNm) = vbBoolean Then Exit Sub
.ScreenUpdating = False
Set P = ws.Pictures.Insert(PNm)
r = P.Height / P.Width 'Get proportionality ratio
P.Width = c.Width
P.Height = r * P.Width
P.Left = c.Left
P.Top = c.Top
c.RowHeight = P.Height
.ScreenUpdating = True
End With
ws.Protect
Set ws = Nothing
Set P = Nothing
Set c = Nothing
End Sub


Regards,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top