访问图表的形状ID - excel vba [英] access a chart's shape ID - excel vba

查看:419
本文介绍了访问图表的形状ID - excel vba的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些背景先。


  1. Excel允许重复的形状名称。也就是说,您可以在同一工作表中同时拥有ChartObject和椭圆形两种形状。您还可以有两个图表,名称为图表2。如果您尝试引用重复名称的形状,例如

  1. 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)。选择

ActiveSheet.Shapes("Dupe").Select,

excel似乎诉诸于返回具有最低ID(和重复名称)的对象。

excel seems to resort to returning the object with the lowest ID (and the duplicate name).

我想创建一个像


函数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.

推荐答案

包含嵌入图表的形状的名称(形状也是chartobject)是:

The name of the shape containing an embedded chart (the shape is also the chartobject) is:

activechart.parent.name

activechart.parent.name

或如果c被声明为图表:

or if c is declared a chart:

c.parent.name

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.

这篇关于访问图表的形状ID - excel vba的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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