[英]How can I add a macro to a Word 2010 or PowerPoint 2010 chart?
In PowerPoint 2010 or Word 2010, when I choose Insert -> Chart, it creates a new chart with an Excel worksheet for the data. 在PowerPoint 2010或Word 2010中,当我选择“插入” - >“图表”时,它会创建一个带有Excel工作表的新图表。
If I add a macro to the Excel worksheet, this seems to be discarded when I close the worksheet and re-open it. 如果我将一个宏添加到Excel工作表,当我关闭工作表并重新打开它时,这似乎被丢弃了。
However, it is possible to have a chart with macros, because I also have some Word documents & PowerPoint presentations that I created in Office 2003, which had embedded Excel charts with macros. 但是,它可能有宏的图表,因为我也有一些Word文档和我在Office 2003中,它已经嵌入Excel图表与宏创建PowerPoint演示文稿。 When I converted those to Office 2010, they look just like "normal" Office 2010 charts, but the macros are preserved.
当我将它们转换为Office 2010时,它们看起来就像“普通”Office 2010图表,但宏保留了下来。
It looks to me like the embedded chart that gets created when you choose Insert -> Chart is in the "pptx" format rather than the "pptm" format, and so macros are not saved. 在我看来,当您选择插入时创建的嵌入式图表 - >图表是“pptx”格式而不是“pptm”格式,因此不会保存宏。
(If I query ActiveWorkbook.FileFormat, I get "51", which is "Open Xml Spreadsheet"; this is indeed "pptx", as opposed to "Open Xml Spreadsheet with Macros", which is "52"). (如果我查询ActiveWorkbook.FileFormat,我得到“51”,这是“Open Xml Spreadsheet”;这确实是“pptx”,而不是“用Mac打开Xml电子表格”,即“52”)。
How can I insert a chart with the "pptm" behavior? 如何插入带有“pptm”行为的图表? Or change the behavior of an existing chart?
或者改变现有图表的行为?
NOTE: I do not want to insert a chart "object", since this means that the chart is not editable within the host application (it merely inserts an Excel chart that you need to "open" in order to edit it). 注意:我不想插入图表“对象”,因为这意味着图表在主机应用程序中不可编辑(它只是插入一个需要“打开”以便编辑它的Excel图表)。
Let me give you a head start... I can achieve what I want by the following method: 让我先行一步......我可以通过以下方法实现我想要的目标:
Now you have a "native" Word or PowerPoint 2010 chart, which you can edit directly in Word or PowerPoint. 现在您有一个“本机”Word或PowerPoint 2010图表,您可以直接在Word或PowerPoint中编辑它。 If you click on the chart and choose Chart Tools->Design->Edit Data, then the Excel worksheet that opens has the macros you created in step 4. Success!
如果单击图表并选择图表工具 - >设计 - >编辑数据,则打开的Excel工作表将包含您在步骤4中创建的宏。成功!
Now, does anyone have a simpler way? 现在,有没有人有更简单的方法?
In my opinion you could achieve what you need in the following way: 在我看来,您可以通过以下方式实现您的需求:
(unfortunately, I can't present it with pictures and exact English commands as I'm using local-not English-version of Office) (不幸的是,我不能用图片和确切的英文命令来呈现它,因为我使用的是本地 - 而不是英文版的Office)
(there are chart editing feature available on the Ribbon) (功能区上有图表编辑功能)
*.docm
*.docm
*docm
extension. *docm
扩展名的宏。 Now that the bounty has passed (with no better answers), I'll add the partial answer from my question, in order to be able to close the question. 既然赏金已经过去了(没有更好的答案),我会从我的问题中添加部分答案,以便能够结束这个问题。
Now you have a "native" Word or PowerPoint 2010 chart, which you can edit directly in Word or PowerPoint. 现在您有一个“本机”Word或PowerPoint 2010图表,您可以直接在Word或PowerPoint中编辑它。 If you click on the chart and choose Chart Tools->Design->Edit Data, then the Excel worksheet that opens has the macros you created in step 4. Success!
如果单击图表并选择图表工具 - >设计 - >编辑数据,则打开的Excel工作表将包含您在步骤4中创建的宏。成功!
I'm still interested in being able to do this more directly... 我仍然有兴趣能够更直接地做到这一点......
The issue is with how the charts data is held within the application. 问题在于如何在应用程序中保存图表数据。 Converting and originating are two different processes.
转换和发起是两个不同的过程。 Your data series is basically an array not an excel sheet.
您的数据系列基本上是一个数组而不是Excel工作表。 It just uses excel to display the data to you to edit.
它只是使用excel来显示要编辑的数据。 You need to keep your code in the module for powerpoint/word and access the chart via the shapes object if you do not want to embed a excel sheet.
如果您不想嵌入Excel工作表,则需要将代码保存在powerpoint / word模块中,并通过形状对象访问图表。
Sub GetChartName()
Dim sSlide As Slide
Dim cChart As Chart
Dim sShape As Shape
Set sSlide = PowerPoint.ActivePresentation.Slides(1)
For Each sShape In sSlide.Shapes
If sShape.HasChart Then
Set cChart = sShape.Chart
MsgBox cChart.Name
Set cChart = Nothing
End If
Next
Set sSlide = Nothing
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.