PDA

View Full Version : Search Function with message box (exit sub)



BerkayE
08-13-2019, 08:26 AM
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

John Wilson
08-14-2019, 03:50 AM
Maybe


If MsgBox("On this slide", vbYesNo + vbQuestion, "Search Function") = vbNo Then
Exit Sub
Else
Exit For
End If

BerkayE
08-14-2019, 05:25 AM
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!!

John Wilson
08-14-2019, 05:58 AM
Not on a MsgBox but you can create a custom UserForm which would behave in this way. Small learning curve but useful skill.