访问图表的形状 ID - excel vba
首先介绍一些背景。
Excel 允许形状重复名称。也就是说,您可以在同一个工作表中同时拥有具有完全相同名称的 ChartObject 和椭圆形形状。您还可以将两个图表都命名为“Chart 2”。如果您尝试引用具有重复名称的形状,例如
<块引用>ActiveSheet.Shapes("Dupe").Select,
Excel 似乎会返回具有最低 ID 的对象(以及重复的名称)。
- (据我所知)没有办法将 ActiveChart 与其相应的包含形状链接起来。
我想创建一个像这样的函数
函数 GetAChartsShape(c 作为图表)作为形状,
但我不知道如何实现。其直接用途是格式化选定的图表(因为无法全局更改图表的字体)。当然,这也可能有其他用途。
Some background first.
Excel allows duplicate names for shapes. That is, you can have both a ChartObject and an oval shape in the same worksheet with exactly the same name. You can also have two charts named both "Chart 2". If you try to reference a shape with a duplicate name, e.g.
ActiveSheet.Shapes("Dupe").Select,
excel seems to resort to returning the object with the lowest ID (and the duplicate name).
- There is no way (that I know of) of linking an ActiveChart with its corresponding containing shape.
I want to create a function like
function GetAChartsShape(c as chart) as Shape,
but I don't know how. The immediate use for this would be to format the selected chart (since there is no way of globally changing a chart's font). Of course, this could also have other uses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
包含嵌入图表的形状的名称(该形状也是图表对象)是:
activechart.parent.name
或者如果 c 被声明为图表:
c.parent.name
但当然您知道您不需要选择一个对象对其进行处理,因此只需在
c.parent
上执行您需要执行的操作即可避免重复名称的问题。
The name of the shape containing an embedded chart (the shape is also the chartobject) is:
activechart.parent.name
or if c is declared a chart:
c.parent.name
But of course you know you don't need to select an object to work on it, so just do what you need to do on
c.parent
which avoids the problem of duplicate names.