質問

私はすべてのテキストを抽出し、それをすべて1つの大きなテキストファイルにまとめたいという膨大なPowerPointファイルのセットを持っています。各ソース(PPT)ファイルには複数のページ(スライド)があります。私はフォーマットを気にしません - 言葉だけです。

これは、PPTでJust ^a ^cでファイルを使用して手動で行うことができ、その後にメモ帳で ^vが続くことができました。次に、PPTをページダウンし、PowerPointの各スライドについて繰り返します。 (残念ながら、私はすべてをつかむだけではできません...それから私はsendkeyを使用してコピー /貼り付けました)

しかし、スライドの数が異なるこれらのPPTは何百もあります。

これは一般的なことをしたいと思うように思われますが、どこにも例を見つけることができません。

誰かがこれを行うためのサンプルコードを持っていますか?

役に立ちましたか?

解決

これがあなたを始めるためのいくつかのコードです。これにより、スライド内のすべてのテキストがデバッグウィンドウにダンプされます。ダンプ以外のフォーマット、グループ、または実行することはありません。

Sub GetAllText()
Dim p As Presentation: Set p = ActivePresentation
Dim s As Slide
Dim sh As Shape
For Each s In p.Slides
    For Each sh In s.Shapes
        If sh.HasTextFrame Then
            If sh.TextFrame.HasText Then
                Debug.Print sh.TextFrame.TextRange.Text
            End If
        End If
    Next
Next
End Sub

他のヒント

次の例は、上記のOtakuのコードに基づいてファイルのリストをループするコードを示しています。

Sub test_click2()

Dim thePath As String
Dim src As String
Dim dst As String
Dim PPT As PowerPoint.Application
Dim p As PowerPoint.Presentation
Dim s As Slide
Dim sh As PowerPoint.Shape
Dim i As Integer
Dim f(10) As String

f(1) = "abc.pptx"
f(2) = "def.pptx"
f(3) = "ghi.pptx"

thePath = "C:\Work\Text parsing PPT\"

For i = 1 To 3
  src = thePath & f(i)
  dst = thePath & f(i) & ".txt"

  On Error Resume Next
  Kill dst
  Open dst For Output As #1
    Set PPT = CreateObject("PowerPoint.Application")
    PPT.Activate
    PPT.Visible = True
    'PPT.WindowState = ppWindowMinimized
    PPT.Presentations.Open filename:=src, ReadOnly:=True
    For Each s In PPT.ActivePresentation.Slides
        For Each sh In s.Shapes
            If sh.HasTextFrame Then
                If sh.TextFrame.HasText Then
                    Debug.Print sh.TextFrame.TextRange.Text
                End If
            End If
        Next
    Next
    PPT.ActivePresentation.Close
  Close #1
Next i
Set PPT = Nothing

End Sub
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top