The code below works fine but I can't modify it so that the new picture will have this location and size:
.Top = Rows(1).Top
.Left = Columns(1).Left
.Height = 2.69cm
.Width = 3.59cm
Any help is appreciated.
.Top = Rows(1).Top
.Left = Columns(1).Left
.Height = 2.69cm
.Width = 3.59cm
Any help is appreciated.
VBA Code:
Sub change_picture()
' Change as needed, keep the \ at the end
Const strFolder = "C:\Users\mars\Desktop\Dog\"
Const strPic = "Picture 5"
Const strPicFile = "C:\Users\mars\Desktop\cat.jpg"
Dim strFile As String
Dim wbk As Workbook
Dim wsh As Worksheet
Dim f As Boolean
Dim shp As Shape
Dim t As Single, l As Single, h As Single, w As Single
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
strFile = Dir(strFolder & "*.xls*")
Do While strFile <> ""
Set wbk = Workbooks.Open(Filename:=strFolder & strFile, UpdateLinks:=False)
For Each wsh In Worksheets(Array("C2", "C4", "C6"))
If wsh.ProtectContents Then
f = True
wsh.Unprotect
End If
Set shp = wsh.Shapes(strPic)
'Capture properties of existing picture such as location and size
With shp
t = .Top
l = .Left
h = .Height
w = .Width
.Delete
End With
Set shp = wsh.Shapes.AddPicture(strPicFile, msoFalse, msoTrue, l, t, w, h)
shp.Name = strPic
If f Then
wsh.Protect
f = False
End If
Next wsh
wbk.Close SaveChanges:=True
strFile = Dir
Loop
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub