文件中提取所有文本

文件中提取所有文本

本文介绍了从 VBA 中的 powerpoint 文件中提取所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a huge set of powerpoint files from which I want to extract all the text and just lump it all into one big text file. Each source (PPT) file has multiple pages (slides). I do not care about formatting - only the words.

我可以通过在 PPT 中通过 ^A ^C 和记事本中的 ^V 手动使用文件来完成此操作;然后在 PPT 中向下翻页,并对 PowerPoint 中的每张幻灯片重复此操作.(太糟糕了,我不能只做一个可以抓取所有东西的 ^A ......然后我可以使用 sendkey 复制/粘贴)

I could do this manually with a file by just ^A ^C in PPT, followed by ^V in notepad; then page down in the PPT, and repeat for each slide in the powerpoint. (Too bad I can't just do a ^A that would grab EVERYTHING ... then I could use sendkey to copy / paste)

但是有数百个带有不同数量幻灯片的 PPT.

But there are many hundreds of these PPTs with different numbers of slides.

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

It seems like this would be a common thing to want to do, but I can't find an example anywhere.

有人有示例代码可以做到这一点吗?

Does anyone have sample code to do this?

推荐答案

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

Here's some code to get you started. This dumps all text in slides to the debug window. It doesn't try to format, group or do anything other than just dump.

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

这篇关于从 VBA 中的 powerpoint 文件中提取所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:44