从VBA中的PowerPoint文件中提取所有文本 [英] Extracting all text from a powerpoint file in VBA

查看:793
本文介绍了从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文件中提取所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆