将PPT中的图像转储到Excel的VBA代码

时间:2018-03-28 05:04:47

标签: excel vba powerpoint

我编写了一个宏来将PPT文件的文本解析为Excel,并将每张幻灯片的文本放入连续的Excel行。我还想将每个PPT幻灯片中的图像添加到与该幻灯片文本对应的下一列Excel中。

Sub ExportTextToCSV()
    Dim oPres As Presentation
    Dim oSlides As Slides
    Dim oSld As Slide         'Slide Object
    Dim oShp As Shape         'Shape Object 
    Dim iFile As Integer      'File handle for output
    Dim sTempString As String
    Dim PathSep As String
    Dim Quote As String
    Dim Comma As String

    iFile = FreeFile          'Get a free file number

    #If Mac Then
        PathSep = ":"
    #Else
        PathSep = "\"
    #End If

    Quote = Chr$(34)
    Comma = ","

    Set oPres = ActivePresentation
    Set oSlides = oPres.Slides

    'Open output file
    '**NOTE:**  errors here if original PPT file hasn't been saved

    Open oPres.Path & PathSep & "AllText.CSV" For Output As iFile

    For Each oSld In oSlides    'Loop thru each slide

        For Each oShp In oSld.Shapes                'Loop thru each shape on slide
            'Check to see if shape has a text frame and text
            If oShp.HasTextFrame And oShp.TextFrame.HasText Then
                sTempString = sTempString & Quote & oShp.TextFrame.TextRange.Text & Quote & Comma
            End If
        Next oShp

        ' print the result to file:
        Print #iFile, sTempString

        sTempString = ""
    Next oSld

    'Close output file
    Close #iFile
End Sub 

有没有办法以同样的方式添加图片?

0 个答案:

没有答案