问题描述
我有一个宏,从目录导入图像,并将它们放在excel单元格中,这些单元格足够大,以适应图像宏的代码段在下面: -
'设置缩略图的行高和列宽度
范围(一个& CStr(currRow))RowHeight = ThumbnailSizeRef + 2
列(A)。ColumnWidth =(ThumbnailSizeRef - 5)/ 5'列宽使用字体宽度设置,转换为像素的公式
'添加缩略图
设置sShape = ActiveSheet.Shapes.AddPicture(文件名:= sFilename,LinktoFile:= msoFalse,SaveWithDocument:= msoTrue,Left:= 0 ,顶部:= 0,宽度:= ThumbnailSizeRef,Height:= ThumbnailSizeRef)
'设置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.He ight)/ 2)
这一切都很好。图像根据需要正确显示在单元格中。我可以成功地对单元格进行排序,并且图像可以正确移动。
当我删除整行(右键单击行和删除)时,我遇到的问题是。 ..在这种情况下,图像从行Im删除跳下来并隐藏在下一行的图像后面。
有什么办法,当我删除行图像也被删除?
您可以将图片属性更改为移动并使用单元格大小。因此,当您删除行时,您的图像也将被删除。
在Excel 2007中测试。
另一个解决方案是添加评论并在后台填充图片(请参阅更多信息:)
I have a Macro that imports images from a directory and places them in excel cells that are made just big enough to fit the image in
A snippet of the macro is below:-
'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)
This all works fine. The images display correctly just in the cell as required. I can sort the cells successfully also and the images get moved correctly.
The problem I have is when I Delete an entire Row (right click on the row and delete)...in this situation the image from the row Im deleting jumps down and hides behind the image on the next row.
Is there any way that when I delete the row the image gets deleted as well?
You can change your picture properties to "Move and size with cells". Hence, when you delete your row, your image will be deleted too.Tested in Excel 2007.
Another solution is to add a comment and fill the picture in the background (see more info here : http://www.excelforum.com/excel-general/569566-embed-image-in-cell.html)
这篇关于Excel - 删除行时删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!