Log in

View Full Version : creating a search box in ppt with find and find next



aadedwar
08-12-2016, 10:52 AM
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

John Wilson
08-12-2016, 11:09 AM
Didn't I email you some code?

aadedwar
08-12-2016, 11:14 AM
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.

John Wilson
08-12-2016, 01:06 PM
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

aadedwar
08-12-2016, 01:19 PM
this works great. Is there a way to hide the message box?

John Wilson
08-13-2016, 10:38 AM
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.

Sneha_shah
04-03-2022, 02:51 AM
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

RogerEye1253
05-30-2022, 08:37 AM
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. (https://megamodapk.com/soul-knight-mod-apk/)

Andrew125
06-03-2022, 11:36 PM
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. (https://gbwamod.com/download-fmwhatsapp-apk/)
Yeah, it does exit the sub when you cancel it.

SamT
06-04-2022, 06:41 AM
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.