简体   繁体   English

VBA:如何与 VBA 中的图表交互?

[英]VBA: How to interact with chart from VBA?

To interact with a chart from VBA, I need it's name.要与 VBA 中的图表进行交互,我需要它的名称。 It's usually just called "Chart 1", "Chart 2", etc.它通常被称为“图表 1”、“图表 2”等。

This is just silly.这很愚蠢。 I wnat to name my charts whatever I want, and then access them like .ChartObjects("MyChart") , and so on.我想随意命名我的图表,然后像.ChartObjects("MyChart")等访问它们。

Otherwise, how is a coder supposed to know what is being done when re-reading ones code?否则,编码人员在重新阅读代码时应该如何知道正在做什么?

How to accomplish this in VBA?如何在 VBA 中实现这一点?

If you are creating the charts in VBA you can name them in the code.如果您在 VBA 中创建图表,您可以在代码中命名它们。

You could also refer to them by index, or create a reference when you create them.您还可以通过索引引用它们,或者在创建它们时创建引用。

If you are manually creating them you can change the default name given to them by selecting the chart and entering the name you want in the Name box.如果您手动创建它们,您可以通过选择图表并在名称框中输入您想要的名称来更改给它们的默认名称。

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

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