Search VBA macro PowerPoint
tom_the_cat
-
m@rina Posted messages 27534 Registration date Status Moderator Last intervention -
m@rina Posted messages 27534 Registration date Status Moderator Last intervention -
Hello,
I am looking to create a button in a PowerPoint presentation to open the search dialog box. In other words, during my presentation, I want to click a button that opens a search field where I can type a word to search throughout the entire presentation.
I found this solution on a forum here: http://www.commentcamarche.net/forum/affich 3983418 recherche ctrl f a partir d une macro
Sub boîteIntégrée()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
But when I put it in my macro, it doesn’t work. Nothing happens and my macro code automatically gets replaced by this:
Sub boîteIntégrée()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
----------------------------------------------------------------
Private Sub CommandButton1_Click()
End Sub
So I tried doing this:
Private Sub CommandButton1_Click()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
But at that point, I get an error message telling me:
Method or data member not found
I don’t know VBA, so I’m improvising a bit and now I’m stuck. Can someone help me find the right code please?
Thank you very much.
I am looking to create a button in a PowerPoint presentation to open the search dialog box. In other words, during my presentation, I want to click a button that opens a search field where I can type a word to search throughout the entire presentation.
I found this solution on a forum here: http://www.commentcamarche.net/forum/affich 3983418 recherche ctrl f a partir d une macro
Sub boîteIntégrée()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
But when I put it in my macro, it doesn’t work. Nothing happens and my macro code automatically gets replaced by this:
Sub boîteIntégrée()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
----------------------------------------------------------------
Private Sub CommandButton1_Click()
End Sub
So I tried doing this:
Private Sub CommandButton1_Click()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
But at that point, I get an error message telling me:
Method or data member not found
I don’t know VBA, so I’m improvising a bit and now I’m stuck. Can someone help me find the right code please?
Thank you very much.
Configuration: Windows XP Firefox 3.0.11
16 answers
-
Hello,
is it really useful to create a macro for a search that you can easily call with the shortcut ctrl+F?
Especially since you'll need to put a button on every slide...
Eric -
Yes, it's really useful because when you're in presentation mode, you can't use the shortcut CTRL + F and since the file I'm creating is intended to be in .pps, there won't be a possibility to use the shortcut.
I don't need to paste the macro button on every page, I just want to put it on the first page so I can directly access the pages related to the keywords.
Anyway, yes it's really important. If someone has a solution, it would really help me a lot.
Thank you very much. -
Hi,
I looked closer and PowerPoint did not plan for the display of this dialog box.
A simple search is not recorded by the macro recorder either...
It seems compromised to me and I cannot help you further, sorry.
Eric -
Thank you for your response, Eric. It seemed to me as well that this project was compromised from the start, but I still hold a tiny glimmer of hope to find a solution, so I will continue my research to attempt the impossible. Apparently, someone has managed to find the solution on this forum, so I will try to see if the solution can still work and if someone can help me implement it.
Since this is a project I am building for work, it is quite important. So I won't give up anytime soon.
Thank you, Eric, for trying; can others take a look at this problem?
Thanks in advance. -
Re,
give me the link to the discussion, we'll see...
eric -
Hello,
You give an Excel example with a formula search dialog... That probably won't work for PowerPoint which, as far as I know, doesn't use formulas...
And anyway, as Eriic said, the Dialogs collection does not exist in VBA PowerPoint. So that avenue is a dead end. Given that the Office developers seem to have trouble working together (as we regularly observe), the VBA of different applications doesn't always use the same terms and has different capabilities.
For your problem, you might consider using an InputBox, then using the result from the InputBox to navigate to the slide that contains the word.
But it's not necessarily easy to manage...
Where are the words to find located? In a text box? In a placeholder??
Should we stop at the first word, or should we keep searching???
And what if the word to find doesn't exist? That also needs to be handled.
Wouldn't it be simpler to make keyword suggestions in a combo box rather than letting the user choose anything at the risk of finding nothing? I honestly don't understand this approach of making the user search in a known context. Your presentation isn't as vast as the internet!! :))))
Just for Eriic: if we want to have a button accessible from all slides, it just needs to be placed in the master... So one button is enough ;)
m@rina
--
- "On the office forum, we ask questions about office automation..."
- "Oh really???" -
Well, she even knows PowerPoint, she's amazing this m@rina!! ;-)
Thanks for the info about the mask
eric -
The link to the topic is here: http://www.commentcamarche.net/forum/affich 3983418 recherche ctrl f a partir d une macro
Thank you m@rina for all these constructive remarks. I didn't know that macros were different between several Office products. I thought that VBA was VBA and that it was a standard. You taught me something.
In reality m@rina, it’s not really a presentation I want to make. It's a bit complicated to explain, but basically, I want to build a guide for the people who join the company where I work. This guide will be interactive and distributed on different PCs, none of which have administrator rights. So I can't make a real program, but I think I can still manage to do something decent with PowerPoint.
The end goal would be something with buttons that allow access to information. Like you open the .pps and you land on a homepage that asks you what information you want to find. Information regarding: "Clients", "Suppliers", "Accounting"...
Then let's say you click on "Clients". You have new buttons: "Prospecting", "Partnerships", ...
So it’s going to take me time to make something like this because there will be a lot of information in it from many different areas. That’s why this idea of a search field seems useful.
My explanatory texts will be directly on the slides in text boxes. I would like, for example, to be able to type in my search field "VAT" and that it directly leads to the page explaining how we should handle VAT.
Is there any tiny chance that I can find a solution to my problem? -
I was wondering if anyone had found a trick to use Excel dialog boxes from another Office app, but no, the link you provided doesn't help.
Inspired by PowerPoint help on .find, here's a start: search.ppt
It's just a feasibility test; it would need to be cleaner and replace the msgbox with a userform, among other things...
I still think a slide with a list of keywords would be more suitable.
Making it in a 'word cloud' style (different word sizes and a gradient of blue, large and dark for concepts, smaller and lighter for details where the word is just mentioned) could look nice and professional as well...
eric
PS: just 2 words to search for: VAT and prospecting) -
Hello,
Without much thought (well, it's Sunday and it's too hot...), at first glance, I would say it's a bad idea...
PowerPoint is a PreO software, I think we should leave it with its own functions without forcing it to do things it shouldn't... I know PowerPoint is very popular right now, and I see all sorts of things that aren't very coherent...
I did just attempt to create this macro, but we need to differentiate between the macros that work during a slideshow and those that work outside of it. This macro still needs a lot of improvement.
Sub search() Dim Message, title, response Message = "What do you want to search for?" Title = "Search" response = InputBox(Message, title) For Each slide In Application.ActivePresentation.Slides For Each shape In slide.Shapes If shape.HasTextFrame Then Set txtRng = shape.TextFrame.TextRange Set found = txtRng.Find(FindWhat:=response) Do While Not (found Is Nothing) SlideShowWindows(1).View.GotoSlide slide.SlideNumber Exit Do Loop End If Next Next End Sub
Personally, I would opt for a Word document with a properly detailed outline using heading styles, and I would convert everything into a PDF with the bookmarks tab on the left so you can click from anywhere on the chapter you're interested in. Furthermore, in a PDF, it's easy to search for words.
In PowerPoint, if someone searches for "Partenariats" instead of "partenariat," for example, they might not find anything.... I think a detailed table of contents is much more interesting.
m@rina
Wink for Eriic:
https://www.amazon.fr/s/ref=nb_ss_w?__mk_fr_FR=%C5M%C5Z%D5%D1&url=search-alias%3Dstripbooks&field-keywords=powerpoint+mathias
--
- "On the office forum, we ask questions about office automation..."
- "Oh really???" -
Uh... if I read correctly, it is mentioned that the presentation should be a PPS, so I suppose it is intended to be used with a viewer, right? If that is the case, it seems to me that macros are not executed, are they?
-
Thank you both for your help and your thoughts. I still want to test my initial idea and if I see that it's not an ideal solution, I'll go for one of your ideas (PDF or keyword cloud).
However, I tried both of your codes and nothing happens when I paste them into my VBA editor. Do I need to do something special before I can use the VBA codes (like an electronic signature or something like that which I've crossed paths with in my little life)?
I tried this for Marina's code:
Private Sub CommandButton1_Click()
Dim Message, title, response
Message = "What do you want to search?"
Title = "Search"
response = InputBox(Message, title)
For Each slide In Application.ActivePresentation.Slides
For Each shape In slide.Shapes
If shape.HasTextFrame Then
Set txtRng = shape.TextFrame.TextRange
Set found = txtRng.Find(FindWhat:=response)
Do While Not (found Is Nothing)
SlideShowWindows(1).View.GotoSlide slide.SlideNumber
Exit Do
Loop
End If
Next
Next
End Sub
And this for Eric's code:
Private Sub CommandButton1_Click()
word = InputBox("Word to search")
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
Set foundText = txtRng.Find(FindWhat:=word)
Do While Not (foundText Is Nothing)
With foundText
.Font.Bold = True
Set foundText = _
txtRng.Find(FindWhat:="CompanyX", _
After:=.Start + .Length - 1)
End With
SlideShowWindows(1).View.GotoSlide (sld.SlideIndex)
r = MsgBox("Next", vbOKCancel)
If r = vbCancel Then Exit For
Loop
End If
Next
If r = vbCancel Then Exit For
Next
End Sub
The codes do not give me error messages, but nothing happens when I click on the button. I'm sorry for being such a bother and troubling you with this on a Sunday afternoon, but your help is really valuable to me, especially since I had never opened a VBA editor before yesterday.
I understand the lines of code you made for me (thank you a thousand times) but it still doesn't work. I think it's me who is making a mistake somewhere... -
re, re,
@ katimini: it's true that I hadn't tried that, I just did. It's also okay for a .pps
@ m@rina: oh well, you do have several strings to your bow ;-) But I don't think I'll specialize in macros under PowerPoint.
It's more out of curiosity and since Tom seems to be investing himself on his side that I'm trying with my means to help him a bit to unblock :-)
I'll rather invest in Word 2007 for the girls (but I am indeed a boy who feels deeply heterosexual, it's for a gift) :-)
@ tom: if nothing happens with the file I uploaded, it's that your security is too high.
menu 'tools / options...', tab 'security' button 'macro security...' choose 'medium'. Then open the file.
eric -
Oh yes, I thought there was something like that.
It's perfect, I can manage with that. Thank you very much for your help, I will try in that direction to see if it can lead to something.
Thanks everyone! -
eriic, it works WITH PowerPoint whether in PPS or PPT, but macros do not work with the viewer alone!
-
Good evening,
Oh yes, it should have been specified that it was for use with the viewer, because, indeed, macros do not work with the viewer.
m@rina
--
- "On the office forum, questions about office work are asked..."
- "Really???"