Dav*_*vid 3 excel vba excel-vba
我有一个宏从目录导入图像,并将它们放在excel单元格中,这些单元格的大小足以容纳图像
宏的片段如下: -
'Set the Row Height and Column Width of the thumbnail
Range("A" & CStr(currRow)).RowHeight = ThumbnailSizeRef + 2
Columns("A").ColumnWidth = (ThumbnailSizeRef - 5) / 5 'Column Width uses a font width setting, this is the formula to convert to pixels
'Add the thumbnail
Set sShape = ActiveSheet.Shapes.AddPicture(Filename:=sFilename, LinktoFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=ThumbnailSizeRef, Height:=ThumbnailSizeRef)
'Set the Left and Top position of the Shape
sShape.Left = Range("A" & CStr(currRow)).Left + ((Range("A" & CStr(currRow)).Width - sShape.Width) / 2)
sShape.Top = Range("A" & CStr(currRow)).Top + ((Range("A" & CStr(currRow)).Height - sShape.Height) / 2)
Run Code Online (Sandbox Code Playgroud)
一切正常.根据需要,图像只在单元格中正确显示.我也可以成功地对单元格进行排序,并且图像可以正确移动.
我遇到的问题是当我删除整行时(右键单击行并删除)...在这种情况下,行删除中的图像向下跳跃并隐藏在下一行的图像后面.
有没有办法当我删除行时图像也被删除?
您可以将图片属性更改为"移动并使用单元格调整大小".因此,当您删除行时,您的图像也将被删除.在Excel 2007中测试.
另一种解决方案是添加注释并在后台填写图片(请参阅此处的更多信息:http://www.excelforum.com/excel-general/569566-embed-image-in-cell.html)