根据Powerpoint中的关键字选择幻灯片

发布于 2025-01-12 16:20:08 字数 826 浏览 2 评论 0原文

我正在尝试创建一个宏,该宏将选择标题中包含关键字的任何幻灯片,但没有任何结果。该 ppt 包括不同的首页、免责声明和内容幻灯片,其想法是向每张幻灯片的标题添加关键字,并使用宏来选择所选幻灯片并将其导出为 PDF。

我已经使导出部分正常工作,但需要手动输入幻灯片编号。

我从类似的问题中获得了下面的代码,但无法重写它以选择幻灯片而不是将答案呈现为 MsgBox。有人可以帮忙吗?

Sub FindText()
Dim sld As Slide, shp As Shape, list As String, myPhrase As String
myPhrase = InputBox("enter a phrase", "Search for what?")

For Each sld In Application.ActivePresentation.Slides
    For Each shp In sld.Shapes
        If shp.HasTextFrame Then
            If Left(shp.Name, 5) = "Title" Then
                If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then
                    If list = "" Then list = sld.Name Else list = list & ", " & sld.Name
                End If
            End If
        End If
    Next shp
Next sld
MsgBox list

End Sub

I'm trying to create a macro that will select any slide that contains a keyword in the title, but not getting anywhere. The ppt includes different frontpages, disclaimers and content slides and the idea is to add keywords to the titles of each slide and get the macro to select and export the selected slides to PDF.

I've got the export part working, but have the enter the slide numbers manually.

I got the code below from a similar question, but can't rewrite it to select the slides instead of presenting the answers as a MsgBox. Can somebody help, please?

Sub FindText()
Dim sld As Slide, shp As Shape, list As String, myPhrase As String
myPhrase = InputBox("enter a phrase", "Search for what?")

For Each sld In Application.ActivePresentation.Slides
    For Each shp In sld.Shapes
        If shp.HasTextFrame Then
            If Left(shp.Name, 5) = "Title" Then
                If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then
                    If list = "" Then list = sld.Name Else list = list & ", " & sld.Name
                End If
            End If
        End If
    Next shp
Next sld
MsgBox list

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那请放手 2025-01-19 16:20:08

我的完整代码,使用史蒂夫的解决方案,如果有人试图解决同样的问题:

Sub SelectedSlidesToPDF()
    
  Dim sld As Slide, shp As Shape, list As String, myPhrase As String

myPhrase = "WhatYouLookFor"

    For Each sld In Application.ActivePresentation.Slides

' FIRST, hide the slide:
sld.SlideShowTransition.Hidden = True

        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If Left(shp.Name, 5) = "Title" Then
                    If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then

' UNHIDE the slides that contain your keywords
sld.SlideShowTransition.Hidden = False

                End If
            End If
        End If
    Next shp
Next sld

'EXPORT slides
  ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & "MySelectedSlides " & Format(DateSerial(Year(Date), Month(Date) - 1, 1), "yyyy-mm") & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint, RangeType:=ppShowAll

    
' UNIHDE all slides in presentation
For Each sld In ActivePresentation.Slides
        sld.SlideShowTransition.Hidden = msoFalse
    Next sld

End Sub

My full code, using Steve's solution, if anyone is trying to solve the same problem:

Sub SelectedSlidesToPDF()
    
  Dim sld As Slide, shp As Shape, list As String, myPhrase As String

myPhrase = "WhatYouLookFor"

    For Each sld In Application.ActivePresentation.Slides

' FIRST, hide the slide:
sld.SlideShowTransition.Hidden = True

        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If Left(shp.Name, 5) = "Title" Then
                    If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then

' UNHIDE the slides that contain your keywords
sld.SlideShowTransition.Hidden = False

                End If
            End If
        End If
    Next shp
Next sld

'EXPORT slides
  ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & "MySelectedSlides " & Format(DateSerial(Year(Date), Month(Date) - 1, 1), "yyyy-mm") & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint, RangeType:=ppShowAll

    
' UNIHDE all slides in presentation
For Each sld In ActivePresentation.Slides
        sld.SlideShowTransition.Hidden = msoFalse
    Next sld

End Sub
镜花水月 2025-01-19 16:20:08

默认情况下,当您另存为 PDF 时,PDF 不会包含任何隐藏的幻灯片,因此您只需先隐藏所有幻灯片,然后取消隐藏要包含在 PDF 中的任何幻灯片即可。虽然我没有在这里执行此操作,但在保存为 PDF 后,您将需要再次取消隐藏所有幻灯片。

    For Each sld In Application.ActivePresentation.Slides

' FIRST, hide the slide:
sld.SlideShowTransition.Hidden = True

        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If Left(shp.Name, 5) = "Title" Then
                    If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then

' UNHIDE the slides that contain your keywords
sld.SlideShowTransition.Hidden = False                        
                    End If
                End If
            End If
        
        Next shp
    Next sld

By default, when you save as PDF, the PDF won't include any slides that are hidden, so you can simply hide all the slides first, then UNHIDE any that you want to include in the PDF. While I haven't done this here, you'll want to UNHIDE all the slides again after saving to PDF.

    For Each sld In Application.ActivePresentation.Slides

' FIRST, hide the slide:
sld.SlideShowTransition.Hidden = True

        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If Left(shp.Name, 5) = "Title" Then
                    If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then

' UNHIDE the slides that contain your keywords
sld.SlideShowTransition.Hidden = False                        
                    End If
                End If
            End If
        
        Next shp
    Next sld
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文