Consulting

Results 1 to 4 of 4

Thread: Search Function with message box (exit sub)

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

    Question Search Function with message box (exit sub)

    Hello, I'm trying to get this search function to have a quit option, i.e. stop/cancel when clicked on no. The search and search next is working perfectly, but as soon as I add the the if response for the message box, it's not working. Thanks!!!

    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
    Dim MsgBoxResult As Long
    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", vbYesNo + vbQuestion, "Search Function"
                         If response = vbNo Then
                         Exit Sub
                         ElseIf response = vbYes Then
                         Exit For
                      End If
                   End If
                End If
             Next oshp
          Next osld
    
    
       MsgBox "Finished"
       Me.TextBox1.Text = ""
    End If
    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Maybe

    If MsgBox("On this slide", vbYesNo + vbQuestion, "Search Function") = vbNo Then
                         Exit Sub
                         Else
                         Exit For
                         End If
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Aug 2019
    Posts
    3
    Location
    Quote Originally Posted by John Wilson View Post
    Maybe

    If MsgBox("On this slide", vbYesNo + vbQuestion, "Search Function") = vbNo Then
                         Exit Sub
                         Else
                         Exit For
                         End If
    Thank you VERY much! Btw is there a way to have show next and show previous result? (e.g. next and previous buttons on the msgbox?)

    Thanks again!!

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Not on a MsgBox but you can create a custom UserForm which would behave in this way. Small learning curve but useful skill.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

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