6

我有大量的 powerpoint 文件,我想从中提取所有文本,然后将它们全部集中到一个大文本文件中。每个源 (PPT) 文件都有多个页面(幻灯片)。我不关心格式 - 只有单词。

我可以通过 PPT 中的 ^A ^C 和记事本中的 ^V 手动处理文件;然后在 PPT 中向下翻页,并对 powerpoint 中的每张幻灯片重复。(太糟糕了,我不能只做一个 ^A 来抓住一切......然后我可以使用 sendkey 来复制/粘贴)

但是这些 PPT 有数百个,幻灯片数量不同。

这似乎是一件很常见的事情,但我在任何地方都找不到一个例子。

有没有人有示例代码来做到这一点?

4

2 回答 2

5

这里有一些代码可以帮助您入门。这会将幻灯片中的所有文本转储到调试窗口。除了转储之外,它不会尝试格式化、分组或做任何事情。

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
于 2011-01-13T01:36:42.517 回答
1

以下示例显示了根据上面给出的 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
于 2011-01-18T21:59:18.283 回答