Consulting

Results 1 to 10 of 10

Thread: creating a search box in ppt with find and find next

  1. #1
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location

    creating a search box in ppt with find and find next

    I want to set up a search box in my slide master so that the user can search easily while in slide show mode. Because of a lot of hyperlinks, animations, etc, I want to keep them in slide show mode. I was able to find the code below that works, but only takes you to the first instance. I want the user to find the next instance and the next until there are no more. Not looking to find and replace. just find and find next. What do I need to change in the code below?


    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Dim osld As Slide
    Dim oshp As Shape
    Dim b_found As Boolean
    If KeyCode = 13 Then 'ENTER PRESSED
    If Me.TextBox1.Text <> "" Then
    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    If oshp.HasTextFrame Then
    If oshp.TextFrame.HasText Then
    If InStr(UCase(oshp.TextFrame.TextRange), UCase(Me.TextBox1.Text)) > 0 Then
    SlideShowWindows(1).View.GotoSlide (osld.SlideIndex)
    Me.TextBox1.Text = ""
    b_found = True
    Exit For
    End If
    End If
    End If
    Next oshp
    If b_found = True Then Exit For
    Next osld
    End If
    If b_found = False Then MsgBox "Not found"
    End If
    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Didn't I email you some code?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location
    yeas you did. Thanks. unfortunately it didn't work for me. a message came up on each slide that said found on slide, even though the text was not on that slide. When you click on the x to close the box it just goes to the next slide with the same result.

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I think I said it was "top of head" and would need some work. This should be closer

    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)   
    Dim strToFind As String
       Dim osld As Slide
       Dim oshp As Shape
    If KeyCode = 13 Then      'ENTER PRESSED
          strToFind = UCase(Me.TextBox1.Text)
          For Each osld In ActivePresentation.Slides
             For Each oshp In osld.Shapes
                If oshp.HasTextFrame Then
                   If oshp.TextFrame.HasText Then
                      If InStr(UCase(oshp.TextFrame.TextRange), strToFind) > 0 Then
                         SlideShowWindows(1).View.GotoSlide (osld.SlideIndex)
                         MsgBox "On this slide"
                         Exit For
                      End If
                   End If
                End If
             Next oshp
          Next osld
    
    
       MsgBox "Finished"
       Me.TextBox1.Text = ""
       End If
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location
    this works great. Is there a way to hide the message box?

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Not with a message box. If you have some programming skill you could create a small user form and have it appear off the main slide area. If it just had a command button set to run code unload userform that would work (Press |ENTER to move on). Not easy to explain though or demo if you don't code or don't have someone to show you.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7

    Adding Cancel option

    Hi there, I wanted to add an option to the msg box so that the user sees ok and cancel so I added these attributes to the msg box line.

    However could you help advise how I can add an action so that if the user selects ‘Cancel’ at any point during the search matches then it exits sub. In my case the user may not want to go through the entire string of matches.

    I’m still learning but essentially I wanted to do something like this but not sure where to insert this code.

    Answer = Msgbox (“Match found on slide”, vbOKCancel)
    if Answer = vbCancel
    With SlideshowWindows (1).view
    .gotoslide 3
    end with
    Exit sub
    End if

  8. #8
    I am also looking to add an action, if someone selected cancel during the search matches it should exit the sub. Please let me know if someone knows about it.

  9. #9
    Quote Originally Posted by RogerEye1253 View Post
    I am also looking to add an action, if someone selected cancel during the search matches it should exit the sub. Please let me know if someone knows about it.
    Yeah, it does exit the sub when you cancel it.

  10. #10
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    A six year old thread. Most of the original posters have left the train.

    Post a new thread/question, and provide a link to this one.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •