我试图创建一个宏,它需要工作表A列中的图像链接,粘贴关联的图像,然后更改每行的行高以匹配高度该行中的图片。VBA匹配行高度粘贴图像大小
我得到了粘贴部分,但无法弄清楚如何设置rowheight。我已经尝试了十几种不同的方式,但不断设置“无法设置Range类的RowHeight属性”错误。这是代码。
Sub ConvertLinktoImage()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Dim LastCell As String
LastCell = "A" & LastRow
Dim ImageHeight As Long
Dim RowRange As Range
Set RowRange = ActiveSheet.Range("A1:" & LastCell)
Dim ImageShape As Shape
For Each cell In RowRange
filenam = cell.Value
ActiveSheet.Pictures.Insert(filenam).Select
Set ImageShape = Selection.ShapeRange.Item(1)
ImageHeight = ImageShape.Height
With ImageShape
.LockAspectRatio = msoTrue
.Cut
End With
Cells(cell.Row, cell.Column).PasteSpecial
cell.RowHeight = ImageHeight
Next cell
Application.ScreenUpdating = True
End Sub
感谢您的帮助!
试试这样说:'行(cell.Row).EntireRow.RowHeight = ImageHeight' – gizlmo