Excel 调整图片宽度和高度
我正在尝试插入一张图片,并根据单元格的宽度和高度调整大小,然后将其放置在单元格上 这是子程序Excel 调整图片宽度和高度,excel,vba,image,Excel,Vba,Image,我正在尝试插入一张图片,并根据单元格的宽度和高度调整大小,然后将其放置在单元格上 这是子程序 Sub insertPictures(vPath, cellAddress) Dim img As Picture, r As Range Set img = IREP.Pictures.Insert(vPath) Set r = IREP.Range(cellAddress) With img .ShapeRange.LockAspectRatio = msoFalse .Top
Sub insertPictures(vPath, cellAddress)
Dim img As Picture, r As Range
Set img = IREP.Pictures.Insert(vPath)
Set r = IREP.Range(cellAddress)
With img
.ShapeRange.LockAspectRatio = msoFalse
.Top = r.Top
.Left = r.Left
.Width = r.Width
.Height = r.Height
End With
End Sub
它将图片插入到应该的位置,但不会调整高度或宽度,正如我这样做时在下面的屏幕截图中看到的那样
调用PForm.insertPictures(“C:\Users\vksk0\Pictures\Screenshots\Screen.png”、“frontPic”)
测试子例程
看起来您正试图将图像定位在合并范围内,因此请尝试
.Width = r.MergeArea.Width
.Height = r.MergeArea.Height
什么是
IREP
?@dwirony工作表的代码名,如项目工作区窗口中的屏幕截图所示。