パワーポイントからテキストを抽出する

パワーポイントからテキストを抽出する

そこで、この素晴らしいスクリプトを見つけました: http://www.pptfaq.com/FAQ00274_Export_Text_to_a_text_file-_extract_text_from_PowerPoint_-Mac_or_PC-.htm (私は2番目を使っています)

インポート部分は次のとおりです。

 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
        If oShp.Type = msoPlaceholder Then
            Select Case oShp.PlaceholderFormat.Type
                Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
                    Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderBody
                    Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderSubtitle
                    Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
                Case Else
                    Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
            End Select
        Else
            Print #iFile, vbTab & oShp.TextFrame.TextRange
        End If  ' msoPlaceholder
      Else  ' it doesn't have a textframe - it might be a group that contains text so:
        If oShp.Type = msoGroup Then
            sTempString = TextFromGroupShape(oShp)
            If Len(sTempString) > 0 Then
                Print #iFile, sTempString
            End If
        End If
      End If    ' Has text frame/Has text

    Next oShp

すでに少し変更しているので、出力ファイルには「タイトル」、「その他のプレースホルダー」などのテキストは含まれず、タブ (「vbTab」) も挿入されません。ただし、各行 (または段落) は出力ファイルの新しい行に配置されます。

質問:スクリプトに「スライド」/「本文」のすべての「コンテンツ」を同じ行/セルにダンプするように指示するにはどうすればよいですか?

このスクリプト(そしてこのhttp://www.pptfaq.com/FAQ00332_Export_Slide_Number_and_Title_Text_to_a_text_file.htm) は、タイトルに対して、「body」または「ppPlaceholderBody」に対してのみこの動作を示します。

なぜそうなるのか、違いは何なのか、私には全く分かりません。同じ図形/ボックスであっても、2 行または 2 つの箇条書きの違いが分からないだけなのでしょうか? 私の目標は、複数の .ppt で一貫した行/セル番号を設定し、スライド 2 に 1 行追加しても、スライド 5 のコンテンツが次の行に移動されないようにすることです。

助けてくれてありがとう!

答え1

現在、PowerPoint のインストールがダウンしているため、これはテストされていません。しかし...

文字列変数を作成してそれに追加し、スライドが終わったらその文字列を Excel セルにコピーするだけです。

Dim slideText As String
For Each oShp In oSld.Shapes                 'Loop thru each shape on slide
    If Len(slideText) > 0 Then
        '--- strip the unneeded trailing CRLF
        slideText = Left$(slideText, Len(slideText) - 2)
        '--- now copy the string to the appropriate cell in Excel
    Else
        '--- clear the string for the next slide
        slideText = vbNullString
    End If

    'Check to see if shape has a text frame and text
    If oShp.HasTextFrame Then
        If oShp.TextFrame.HasText Then
            If oShp.Type = msoPlaceholder Then
                Select Case oShp.PlaceholderFormat.Type
                    Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
                        slideText = slideText & "Title:" & vbTab & _
                                    oShp.TextFrame.TextRange & vbCrLf
                    Case Is = ppPlaceholderBody
                        slideText = slideText & "Body:" & vbTab & _
                                    oShp.TextFrame.TextRange & vbCrLf
                    Case Is = ppPlaceholderSubtitle
                        slideText = slideText & "SubTitle:" & vbTab & _
                                    oShp.TextFrame.TextRange & vbCrLf
                    Case Else
                        slideText = slideText & "Other Placeholder:" & _
                                    vbTab & oShp.TextFrame.TextRange & vbCrLf
                End Select
            Else
                slideText = slideText & vbTab & oShp.TextFrame.TextRange
            End If                           ' msoPlaceholder
        End If
    Else
        ' it doesn't have a textframe - it might be a group that contains text so:
        If oShp.Type = msoGroup Then
            sTempString = TextFromGroupShape(oShp)
            If Len(sTempString) > 0 Then
                slideText = slideText & sTempString & vbCrLf
            End If
        End If
    End If                                   ' Has text frame/Has text
Next oShp

'--- catch the text on the last slide here
If Len(slideText) > 0 Then
    '--- strip the unneeded trailing CRLF
    slideText = Left$(slideText, Len(slideText) - 2)
    '--- now copy the string to the appropriate cell in Excel
End If

もちろん、スライドごとにこのループを実行します。

答え2

これは役に立たないと思いますが、次のとおりです。https://stackoverflow.com/questions/45468824/ppt-vba から Excel スプレッドシートへの印刷 Lbound と Ubound を使用して特定のセルに印刷する同様の操作を試みます。

複数の ppt/xls にわたってセルが一貫している限り、文字列がどこに入るかはわかりません...

(特定の xls ファイルも選択されますが、印刷ごとに新しいファイルを作成したいのですが、指定されたファイルを作成するか、ppt からファイル名を使用する既存のコードでは問題にならないはずです。)

関連情報