Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 调整图片宽度和高度_Excel_Vba_Image - Fatal编程技术网

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工作表的代码名,如项目工作区窗口中的屏幕截图所示。