在VBA中调整图像大小保持高宽比

我有一个VBAmacros,用于文件中的图像,并将其粘贴到Excel电子表格中,名为“国家/地区configuration文件”的工作表中。 我想调整图像的大小,使其宽度为350px,同时保持宽高比。

这是我写的代码:

Public Sub Macro15() Dim picname As String Dim shp As Shape Dim present As String Sheets("Country Profile").Activate Sheets("Country Profile").Select ActiveSheet.Pictures.Delete Cells(19, 40).Select 'This is where picture will be inserted (column) picname = Sheets("REPORT ON").Range("A2").Value 'This is the picture name Cells(19, 46).Select Call ActiveSheet.Shapes.AddPicture("C:\Users\" & Environ("UserName") & "\Maps with Cities\" & picname & ".png", _ LockAspectRatio = msoTrue, msoCTrue, Left:=Cells(19, 40).Left, Top:=Cells(19, 46).Top, Width:=350, Height:=-1).Select End Sub 

代码工作,并将图像插入到所需的文件中。 但是,宽高比不保持。 我能做些什么来纠正这个问题?

试试像这样:

 With ActiveSheet.Pictures.Insert(PicPath) .ShapeRange.LockAspectRatio = msoTrue .Width = 350 End With