如何在MS Excel中找到形状? [英] How to find a Shape in MS Excel?

查看:65
本文介绍了如何在MS Excel中找到形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何在MS Excel中的工作表上找到特定形状?

How should /can I find a specific shape on a worksheet in MS Excel?

推荐答案

在这里回答我自己的问题,因为我找不到原始帖子,并且有很多类似的帖子.简而言之,在工作表中找到形状的最佳方法是遍历工作表中的所有形状以找到所需的形状.如:

Answering my own question here as I can't find the original post, and there are numerous similar posts. In short, the best way to find a shape in a sheet is to loop through all the shapes in the sheet to find the one you are looking for. Such as:

...
For Each shp In .Shapes
    arrShapes(shp.ID, 0) = .Cells(shp.TopLeftCell.row, colItemNum).Value
    arrShapes(shp.ID, 1) = shp.TopLeftCell.Address
    arrShapes(shp.ID, 2) = shp.TopLeftCell.row
    arrShapes(shp.ID, 3) = shp.TopLeftCell.Column
Next shp

此代码将所有形状放入数组以供以后搜索.

This code puts all the shapes into an array to search later.

警告!我在使用此代码时发现了一些怪癖!

WARNING! There are a few quirks I found in using this code!

MS Excel使用Shapes作为注释!如果您在单元格中有注释,MS Excel将在工作表的形状中包含该注释!这些是AutoShapeType = msoShapeRectangle,因此很难与其他文本框区分开.您可以在Type = msoComment的情况下对它们进行虚拟化.您可以尝试通过默认名称过滤掉特定注释,该默认名称通常类似于"Commentn"其中n只是一个序列号.不确定如何编号.单元格位置引用(UpperLeft,BottomRight等)是指文本框的位置,用于显示在显示时进行注释"-不是针对父单元格-尽管它们是关闭的.

MS Excel uses Shapes for Comments! If you have a comment in a cell, MS Excel will include this in the shapes for the sheet! These are AutoShapeType=msoShapeRectangle, so hard to distinguish from other text boxes. You can idnetify them where Type = msoComment. You can try to filter out specific comments by their default name, which is usually something like "Commentn" where n is simply a serial number. Not sure how they are numbered. The cell position references (UpperLeft,BottomRight, so on) refer to the placement of the text box for the comment WHEN DISPLAYED - NOT for the parent cell - although they are close.

形状的ID与INDEX不同.例如,我在工作表中找到的第一个形状(包含3个实际形状和2个注释)的ID为15361!不是我所期望的1-5.

The ID for shapes is not the same as the INDEX. For example, the first shape in a sheet that I found (containing 3 actual shapes & 2 comments) had an ID of 15361! Not the 1-5 I was expecting.

相应的代码.

这篇关于如何在MS Excel中找到形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆