我正在为一些简单的数据分析编写一个小的excel加载项,但不幸的是我不是VBA程序员;)

我到目前为止所做的事情:

  • 从巨大的Excel工作簿中获取数据并执行计算
  • 将结果写入预先格式化好的excel'skeleton'文件

  • 我接下来要做什么:
  • 将同样的数据写入也已经整齐准备好的ppt 幻灯片的
    直接从excel vba代码中。

  • 我认为有可能在幻灯片中定义某种文本框,然后将值放入其中...只是还没有发现任何东西!

    在这方面的任何帮助表示赞赏;)

    这是excel&powerpoint 2007,但我想尽可能做到与版本无关。

    TIA

    最佳答案

    这是我在Mahipal Padigela's VBA website上找到的一些代码

    (StackOverFlow上也引用了它)

    ''# Code by Mahipal Padigela
    ''# Open Microsoft Powerpoint,Choose/Insert a Table type Slide(No.4), then double click to add a...
    ''# ...Table(3 Cols & 2 Rows) then rename the Table to "Table1", Save and Close the Presentation
    ''# Open Microsoft Excel, add some test data to Sheet1(This example assumes that you have some data in...
    ''# ... Rows 1,2 and Columns 1,2,3)
    ''# Open VBA editor(Alt+F11),Insert a Module and Paste the following code in to the code window
    ''# Reference 'Microsoft Powerpoint Object Library' (VBA IDE-->tools-->references)
    ''# Change "strPresPath" with full path of the Powerpoint Presentation created earlier.
    ''# Change "strNewPresPath" to where you want to save the new Presnetation to be created later
    ''# Close VB Editor and run this Macro from Excel window(Alt+F8)
    
    Dim oPPTApp As PowerPoint.Application
    Dim oPPTShape As PowerPoint.Shape
    Dim oPPTFile As PowerPoint.Presentation
    Dim SlideNum As Integer
    Sub PPTableMacro()
        Dim strPresPath As String, strExcelFilePath As String, strNewPresPath As String
        strPresPath = "H:\PowerPoint\Presentation1.ppt"
        strNewPresPath = "H:\PowerPoint\new1.ppt"
    
        Set oPPTApp = CreateObject("PowerPoint.Application")
        oPPTApp.Visible = msoTrue
        Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
        SlideNum = 1
        oPPTFile.Slides(SlideNum).Select
        Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table1")
    
        Sheets("Sheet1").Activate
        with oPPTShape.Table
            .Cell(1, 1).Shape.TextFrame.TextRange.Text = Cells(1, 1).Text
            .Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1, 2).Text
            .Cell(1, 3).Shape.TextFrame.TextRange.Text = Cells(1, 3).Text
            .Cell(2, 1).Shape.TextFrame.TextRange.Text = Cells(2, 1).Text
            .Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(2, 2).Text
            .Cell(2, 3).Shape.TextFrame.TextRange.Text = Cells(2, 3).Text
        end with
    
        oPPTFile.SaveAs strNewPresPath
        oPPTFile.Close
        oPPTApp.Quit
    
        Set oPPTShape = Nothing
        Set oPPTFile = Nothing
        Set oPPTApp = Nothing
    
        MsgBox "Presentation Created", vbOKOnly + vbInformation
    End Sub
    

    这是有关Automating Powerpoint with VBAhttp://www.mahipalreddy.com/vba/ppvba.htm的一些额外帮助

    要获取各个幻灯片的名称,请尝试以下操作:
    Dim oSlide As Slide
    
    For Each oSlide In ActiveWindow.Presentation.Slides
        Debug.Print oSlide.Name
    Next
    End Sub
    

    那应该为您指明正确的方向! (太可笑了)

    菲利普

    关于vba - 使用VBA将数据从Excel导出到现有的PowerPoint幻灯片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15760629/

    10-12 18:02
    查看更多