Change picture without change image size

chells_free

New Member
Joined
Mar 17, 2022
Messages
4
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. 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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You're getting this error because you've not actually specified which of the `Pictures` on the worksheet you're actually wanting to refer to. If it's the first/only one on the worksheet, add `(1)` after it (I.e. at the end of the line assigning it to the `v` variable)
 
Upvote 0
You're getting this error because you've not actually specified which of the `Pictures` on the worksheet you're actually wanting to refer to. If it's the first/only one on the worksheet, add `(1)` after it (I.e. at the end of the line assigning it to the `v` variable)
Does this include the picture in the header?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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