我有一个包含21个嵌入式电子表格的PowerPoint,用于填充PowerPoint中的图表。每周将来自两个电子表格的数据复制到嵌入式电子表格中,以使用新数据更新图表。我已经开始研究宏来自动化这个过程。我有宏用新数据打开电子表格,复制数据,然后打开第一个嵌入文件。我收到了运行时错误'''对象在粘贴功能上不支持此属性或方法。
注意:我知道链接的电子表格是可取的,但我的客户想要嵌入的Excel文件。
Sub UpdatedEmbeddedSpreadsheets()
Dim oData As ChartData
Dim oCht As Chart
Dim xlApp As Object
Dim xlWorkBook As Object
'Open Weekly File
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkBook = xlApp.Workbooks.Open("C:\abc.xlsx", True, False)
xlWorkBook.sheets("Weekly ABC Chart").Range("B2:B5").Copy
Set xlApp = Nothing
Set xlWorkBook = Nothing
'Open Embedded Spreadsheet
ActivePresentation.Slides(1).Shapes(1).Select
Set oCht = ActiveWindow.Selection.ShapeRange(1).Chart
oCht.ChartData.Activate
Set oData = oCht.ChartData
'The line below has the run-time error '438'
Debug.Print oData.Workbook.sheets("123").End(x1toright).Offset(0,-1).Paste
oData.Workbook.Close
Set oData = Nothing
Set oCht = Nothing
End Sub
第二次尝试:
Sub UpdatedEmbeddedSpreadsheets()
Dim xlApp As Object
Dim xlWorkBook As Object
'Open Weekly File
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkBook = xlApp.Workbooks.Open("C:\abc.xlsx", True, False)
xlWorkBook.sheets("Weekly AVA Chart").Range("B2:B5").Copy
Set xlApp = Nothing
Set xlWorkBook = Nothing
'Open Embedded Spreadsheet
ActivePresentation.Slides(1).Shapes(1).Select
ActiveWindow.Selection.ShapeRange(1).Chart.ChartData.Activate
Dim ChartData As Object
Set ChartData = CreateObject("Excel.Application")
ChartData.Visible = True
ChartData.Workbook.sheets("123").End(xltoright).Offset(0, -1).Paste
ChartData.Workbook.Close
End Sub