chells_free
New Member
- Joined
- Mar 17, 2022
- Messages
- 4
- Office Version
- 365
- 2021
- 2019
- 2016
- Platform
- Windows
I'm trying to run a VBA that replaces a picture without changing the size of the one that already exists. I currenty I whats below but I'm getting a run-time error '1004':Unable to get the Top property of the Pictures class. I'm not sure if it has to do with it being "floating". Please help!
'change picture without change image size
Sub Test()
Dim wsAp As Worksheet
Dim wbA As Workbook
Dim v As Object
Dim strPathPic As String
Dim strPic As String
Set wbA = ActiveWorkbook
Set wsA = Sheets("Agnello")
Set v = ActiveWorkbook.Sheets("Agnello").Pictures
strPathPic = "S:\Payroll Commissions\Ford Sales\Pictures\Agnello.png"
'Capture properties of exisitng picture such as location and size
With v
t = v.Top
l = v.Left
h = v.Height
w = v.Width
End With
ActiveWorkbook.Sheets("Agnello").Picutes.Delete
Set v = wsA.Shapes.AddPicture("S:\Payroll Commissions\Ford Sales\Pictures\Agnello.png", msoFalse, msoTrue, l, t, w, h)
v.Name = strPic
v.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
v.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue
End Sub
'change picture without change image size
Sub Test()
Dim wsAp As Worksheet
Dim wbA As Workbook
Dim v As Object
Dim strPathPic As String
Dim strPic As String
Set wbA = ActiveWorkbook
Set wsA = Sheets("Agnello")
Set v = ActiveWorkbook.Sheets("Agnello").Pictures
strPathPic = "S:\Payroll Commissions\Ford Sales\Pictures\Agnello.png"
'Capture properties of exisitng picture such as location and size
With v
t = v.Top
l = v.Left
h = v.Height
w = v.Width
End With
ActiveWorkbook.Sheets("Agnello").Picutes.Delete
Set v = wsA.Shapes.AddPicture("S:\Payroll Commissions\Ford Sales\Pictures\Agnello.png", msoFalse, msoTrue, l, t, w, h)
v.Name = strPic
v.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
v.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue
End Sub