我想要帮助创建一个宏来在powerpoint 2013中查找文本

时间:2014-03-26 05:04:32

标签: search text macros powerpoint

我想帮助创建一个宏来查找powerpoint 2013中的文本。我在这里和网上找到了一些答案,但没有任何效果(可能是因为他们使用旧办公室2010)我不是专家(老派程序员)我只需要在全屏显示在演示文稿中工作的搜索框。我的演示文稿有近1,600页(是的,不要问为什么或如何在4 gb ram,2.2 ghz笔记本电脑中运行但它确实如此)我尝试了许多代码,但每个人都失败了。这附近有什么帮助吗? (用于反欺凌项目)

这样的东西(在这里找到)

选项明确

Sub HighlightKeywords()     Dim sld As Slide     Dim shp As Shape     Dim txtRng As TextRange,rngFound As TextRange     Dim I As Long,n As Long     昏暗的目标列表

'~~>  Array of terms to search for
TargetList = Array("keyword", "second", "third", "etc")

'~~> Loop through each slide
For Each sld In Application.ActivePresentation.Slides
    '~~> Loop through each shape
    For Each shp In sld.Shapes
        '~~> Check if it has text
        If shp.HasTextFrame Then
            Set txtRng = shp.TextFrame.TextRange

            For i = 0 To UBound(TargetList)
                '~~> Find the text
                Set rngFound = txtRng.Find(TargetList(i))

                '~~~> If found
                Do While Not rngFound Is Nothing
                    '~~> Set the marker so that the next find starts from here
                    n = rngFound.Start + 1
                    '~~> Chnage attributes
                    With rngFound.Font
                        .Bold = msoTrue
                        .Underline = msoTrue
                        .Italic = msoTrue
                        '~~> Find Next instance
                        Set rngFound = txtRng.Find(TargetList(i), n)
                    End With
                Loop
            Next
        End If
    Next
Next

End Sub

1 个答案:

答案 0 :(得分:0)

幻灯片上的任何形状都可以触发宏。假设您在PPTM文件中有一个HelloWorld子。您可以为任何幻灯片添加形状,为其指定“运行宏:行动设置:HelloWorld”。

因此,您可以编写显示用户表单的代码,而不是简单的HelloWorld宏,用户表单可以收集您要搜索的文本。从那里,接下来发生的事情取决于您要搜索的内容以及您想要对结果执行的操作。你没有提到过。