如何使用 VBA 以编程方式修改嵌入式条形图/柱形图?
我正在创建一个 ProcessBook 显示,该显示用一组条目填充嵌入式 Microsoft Office 11.0 电子表格对象 (Office 2003)。然后我计算有关它们的汇总数据;此汇总数据不应以电子表格形式在屏幕上显示,但确实需要用于生成条形图。该数据当前用于填充单独的 Microsoft Office 11.0 电子表格对象。它的组织方式使得每个条形图的标题位于 A 列中,相应的值位于 B 列中。
由于这是 ProcessBook,我什至在访问嵌入对象时遇到了一些困难,但我已经成功嵌入并获得了访问 ChartSpace 对象以及子 ChChart 对象。不幸的是,我不知道如何手动设置条形的值或如何使用 .SetData
或 .SetSpreadsheetData
方法将其指向一个对象我已经住满了
访问 ChartSpace 对象非常简单:ThisDisplay.ChartSpace1
然后我可以添加图表并相当轻松地访问它:
<代码> 将 objChart 调暗为 ChChart
设置 objChart = ThisDisplay.ChartSpace1.Charts.Add(0)
我也可以轻松访问我的电子表格值:
<代码> strBarName = ThisDisplay.sstChartData.Range("A2").Value
intBarVal = ThisDisplay.sstChartData.Range("B2").Value
如何实际设置数据源或手动设置 ChChart 对象中的条形值?或者,如何使用不同的对象来实现相同的目标?
I'm creating a ProcessBook display that populates an embedded Microsoft Office 11.0 Spreadsheet object (Office 2003) with a set of entries. I'm then calculating aggregate data about them; this aggregate data should not be visible in spreadsheet form onscreen, but does need to be used to generate a bar chart. The data is currently being used to populate a separate Microsoft Office 11.0 Spreadsheet object. It's organized such that the title of each bar chart is in column A and the corresponding value is in column B.
Since this is ProcessBook, I've had some difficulty even gaining access to embedded objects, but I've managed to embed and gain access to a ChartSpace object, as well as a child ChChart object. Unfortunately, I can't figure out how to either manually set the values of the bars or how to use the .SetData
or .SetSpreadsheetData
methods to point it to an object that I've populated.
Accessing the ChartSpace object is pretty straightforward: ThisDisplay.ChartSpace1
I can then add a Chart and access it fairly easily:
Dim objChart as ChChart
Set objChart = ThisDisplay.ChartSpace1.Charts.Add(0)
I can access my spreadsheet values pretty easily as well:
strBarName = ThisDisplay.sstChartData.Range("A2").Value
intBarVal = ThisDisplay.sstChartData.Range("B2").Value
How do I actually set the data source or manually set the values of the bars in the ChChart object? Alternatively, how do I use a different object to accomplish the same goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然坚持是这里的关键。我设法确定如何手动添加值以及如何引用现有电子表格对象。这两个示例都大量取自在线 ChChart 文档;我想当我第一次尝试时我只是累了,并且一定在某个地方输错了一些东西。
<代码>
<代码>
Apparently persistence is the key here. I managed to determine how to both add values manually and how to refer to the existing spreadsheet object. Both examples take heavily from the online ChChart documentation; I guess I was just tired when I attempted it in the first place and must have mistyped something somewhere.