I have searched extesively and do not seem to find an answer. I want to update the data in an existing powerpoint chart. So far I am able to open he presentation,select the page, but I am not able to go past the last line below.
我经常搜索,似乎没有找到答案。我想更新现有powerpoint图表中的数据。到目前为止,我能够打开他的演示文稿,选择页面,但我无法通过下面的最后一行。
I need to open the datasheet so I can paste the data there. I was able to do it with a new chart but then the dataseheet opens immediately, but I want to use an existign chart as it will have all formatting as required. I will then do this for multiple charts in multiple pages to update a standard presetation for a new group ofcustomers.
我需要打开数据表,以便将数据粘贴到那里。我能够使用新图表,但随后数据表立即打开,但我想使用existign图表,因为它将根据需要进行所有格式化。然后,我将针对多个页面中的多个图表执行此操作,以更新新的客户组的标准预设。
Can someone show how would I open the datashet so I can select the right cell and paste my new data (whihc omes from Excel). For many reasons I do not want to pasteexcel charts,I want the daa to reside in PowerPoint. This macro is run from the excel file that has the new data.
有人可以展示我将如何打开数据,以便我可以选择正确的单元格并粘贴我的新数据(来自Excel的数据)。由于很多原因我不想使用pasteexcel图表,我希望daa驻留在PowerPoint中。此宏从具有新数据的excel文件运行。
Sub test2()
Set rngData = Range("A1:D6")
Set ObjPPT = CreateObject("PowerPoint.Application")
Set ObjPresentation = ObjPPT.Presentations.Open("C:\Documents and Settings\ewnym5s\My Documents\Document_sample.pptx")
Set ObjSlide = ObjPresentation.Slides(1)
Set mychart = ObjSlide.Shapes("Chart 1").Chart
mychart.Select
Set wb = mychart.ChartData
Set ws = wb.Worksheets(1)
1 个解决方案
#1
6
To open the datasheet you have to select the shape, and then activate the chartdata. And then you can access the workbook. I've modified your code slightly with some comments
要打开数据表,您必须选择形状,然后激活chartdata。然后您可以访问工作簿。我已经用一些注释稍微修改了你的代码
Sub test2()
Set rngData = Range("A1:D6")
Set ObjPPT = CreateObject("PowerPoint.Application")
Set ObjPresentation = ObjPPT.Presentations.Open("C:\Documents and Settings\ewnym5s\My Documents\Document_sample.pptx")
Set ObjSlide = ObjPresentation.Slides(1)
Set mychart = ObjSlide.Shapes("Chart 1").Chart
mychart.Select
'Activate the chart data
mychart.ChartData.Activate
'Retrieve the workbook.
Set wb = mychart.ChartData.Workbook
Set ws = wb.Worksheets(1)
'Do stuff with the workbook then close with save
wb.Close True
end Sub
Incase you do not know this, when you activate the chartdata Excel will open to display the workbook. There is no way to avoid having it at least flicker if you use this method. To make the flicker as brief as possible you could add wb.parent.Visible = false
. If you cannot stand the flicker, I indicated a possible work around in this thread, but it requires the use of OLEObjects and older controls.
如果您不知道这一点,当您激活chartdata时,Excel将打开以显示工作簿。如果使用此方法,则无法避免至少闪烁。要使闪烁尽可能短,您可以添加wb.parent.Visible = false。如果您无法忍受闪烁,我在此线程中指出了可能的解决方法,但它需要使用OLEObjects和较旧的控件。
#1
6
To open the datasheet you have to select the shape, and then activate the chartdata. And then you can access the workbook. I've modified your code slightly with some comments
要打开数据表,您必须选择形状,然后激活chartdata。然后您可以访问工作簿。我已经用一些注释稍微修改了你的代码
Sub test2()
Set rngData = Range("A1:D6")
Set ObjPPT = CreateObject("PowerPoint.Application")
Set ObjPresentation = ObjPPT.Presentations.Open("C:\Documents and Settings\ewnym5s\My Documents\Document_sample.pptx")
Set ObjSlide = ObjPresentation.Slides(1)
Set mychart = ObjSlide.Shapes("Chart 1").Chart
mychart.Select
'Activate the chart data
mychart.ChartData.Activate
'Retrieve the workbook.
Set wb = mychart.ChartData.Workbook
Set ws = wb.Worksheets(1)
'Do stuff with the workbook then close with save
wb.Close True
end Sub
Incase you do not know this, when you activate the chartdata Excel will open to display the workbook. There is no way to avoid having it at least flicker if you use this method. To make the flicker as brief as possible you could add wb.parent.Visible = false
. If you cannot stand the flicker, I indicated a possible work around in this thread, but it requires the use of OLEObjects and older controls.
如果您不知道这一点,当您激活chartdata时,Excel将打开以显示工作簿。如果使用此方法,则无法避免至少闪烁。要使闪烁尽可能短,您可以添加wb.parent.Visible = false。如果您无法忍受闪烁,我在此线程中指出了可能的解决方法,但它需要使用OLEObjects和较旧的控件。