首页 > 解决方案 > 如何从 Excel 工作簿更新 powerpoint 表

问题描述

我正在尝试编写一个从 excel 运行的代码,然后从 c 盘打开一个现有的 excel 和 powerpoint 文件,并使用名为“Oct18”的工作表中的数据更新幻灯片 2 中的 FIRST 表。

以下是我编写的代码,但不知何故它不起作用。我可以知道是否有人知道该怎么做吗?

Sub WriteText_toPPT_Table()
    'Add a reference to Microsoft Powerpoint 12.0 object library
    Dim ppApp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppShp As PowerPoint.Shape
    Dim ppSld As PowerPoint.slide
    Dim xlworkbook As Workbook

    Dim firstsheet As String
    Dim fileDir As String
    Dim excelFile As String


    firstsheet = "Oct18"
    'fileDir = "c:\masterpresentation.pptx"
    'excelFile = "c:\masterexcel.pptx


    '1) Open powerpoint application
    Set ppApp = CreateObject("PowerPoint.Application")
    ppApp.Visible = msoTrue
    Set xlworkbook = Excel.Application.Workbooks.Open(Filename:=excelFile)

    '2) opening an existing presentation
    Set ppPres = ppApp.Presentations.Open(Filename:=fileDir)
    Set exceldir = Excel.Application.Workbooks.Open(Filename:=excelFile)
    ppPres.Slides(2).Shapes(1).Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = xlworkbook.Sheets(firstsheet).Cells(4, 12)
End Sub

标签: excelvba

解决方案


推荐阅读