我有一个包含100个图表的PowerPoint卡片组。每个图表都包含一个嵌入的Excel文件。打开每个嵌入的Excel文件并从其他地方获取数据以粘贴到其中将需要永远。因此,我正在努力实现这一过程的自动化。(考虑到所有研究和咨询公司每天手动完成这项工作,它肯定具有一定的经济价值。)
-
Sub UpdateChartData3()
Dim shp As Shape
Set shp = ActivePresentation.Slides(1).Shapes(1)
Dim cht As Chart
Set cht = shp.Chart
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
'This clear all the data in the embedded excel file for the chart(1)
' in the first slide.
Set wb = cht.ChartData.Workbook
Set ws = wb.Worksheets(1)
ws.Cells.Clear
Dim Databook As Excel.Application
Set Databook = New Excel.Application
Databook.Visible = True
'This opens up an external excel file. Copy a range from the Excel
' file and paste into the embedded excel file
Databook.Workbooks.Open "C:\Folder\Master Slide.xlsx", True, False
ActiveWorkbook.Worksheets("Sheet1").Range("A1").Select
Selection.CurrentRegion.Copy
wb.Activate
Ws.Paste
Set Databook = Nothing
PowerPoint.presentations.slides.shapes.chart.chartdata.workbook.worksheet.range
因此,从逻辑上讲,如果我将代码Ws.paste
(从上面的编码中)更改为下面的内容,它应该可以正常工作,但事实并非如此。
ws.Range("A1").selection
Selection.paste
'This is to expand the source data table of the chart, so that the chart
' in Powerpoint can be automated.
Dim rng As Range
Set rng = Range("A1").CurrentRegion
ws.ListObjects("Table1").Resize ws.rng
真正的问题是缺少PowerPoint VBA文档。有人可以帮忙吗?