ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   I want to insert a picture in an unlocked cell of a protected shee (https://www.excelbanter.com/excel-worksheet-functions/135863-i-want-insert-picture-unlocked-cell-protected-shee.html)

DiamondDave44

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

BoniM

I want to insert a picture in an unlocked cell of a protected shee
 
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.

"DiamondDave44" wrote:

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


Greg Wilson

I want to insert a picture in an unlocked cell of a protected shee
 
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

"DiamondDave44" wrote:

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



All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com