简体   繁体   English

VBA Excel中获取图片的底行

[英]vba excel get picture's bottom row

I have a spreadsheet with a picture. 我有一个带有图片的电子表格。 I don't know the size of the picture (it may vary). 我不知道图片的大小(可能会有所不同)。 I want to to get the last row of the picture in a variable (I want to leave a blank row to the bottom of the picture and start filling data in the next row). 我想在变量中获取图片的最后一行(我想在图片底部保留空白行,并开始在下一行中填充数据)。 Could you help me figure out the syntax? 您能帮我弄清楚语法吗?

I can't even figure out how to get the picture into a variable.. 我什至不知道如何将图片变成变量。

I was able to do this with the following code: 我可以使用以下代码执行此操作:

 Dim testPic As Object
 For Each testPic In ActiveSheet.Pictures
    h = testPic.Height
    cellHeight = Cells(ImageTopRow, ImageLeftCol).Height
    nRows = h/cellHeight
 Next

But: a. 但是: I don't need a foreach, there's only one picture in the collection, I just can't figure out how to get the first one. 我不需要foreach,收藏中只有一张照片,我只是想不出如何获得第一张照片。 b. b。 There should be an easier way, right? 应该有一种更简单的方法,对吗?

Thanks, Li 谢谢李

Dim pic As Shape
Set pic = ActiveSheet.Shapes(1)

MsgBox pic.BottomRightCell.Row

will show you the cell's location of the right bottom corner, ie 将显示您单元格在右下角的位置,即

在此处输入图片说明

Hope this will help. 希望这会有所帮助。

"ActiveSheet.Shapes.Count " - this helps you count the number of pictures in the active sheet "ActiveSheet.Shapes(1)" - you can just use this if you only have 1 Photo or if you want the bottom right of the 1st photo “ ActiveSheet.Shapes.Count”-这可以帮助您计算活动工作表“ ActiveSheet.Shapes(1)”中的图片数量-如果您只有1张照片或想要第1张照片的右下角,则可以使用它照片

Code: 码:

click to view the code Dim pic As Shape 单击以查看代码 Dim pic As Shape

Set pic = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)

'Determines the address on the bottom right of the picture
lLast = pic.BottomRightCell.Address


'Selects the Bottom right cell of the Image/picture
Range(lLast).Select

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM