#1
|
|||
|
|||
Search Button
I want to create a Text box and Search button in ms word. When I enter text in the search box and click the search button the code should find the text searched for. I tried the following code but it is not working.
Public Sub FindWord(sWord As String) With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = sWord .Execute End With End Sub Any help would be greatly appreciated. Thank you. |
#2
|
||||
|
||||
Have you tried recording a macro to see what gets recorded? There is some middle ground between your code and the code that is recorded where you will discover the missing lines that are necessary.
The Find function is sticky which means it remembers earlier find options and it can be good to reset these to ensure then don't get in the way of your code.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
You can find a sample of a find and replace macro (in this case to replace the characters "><" with a paragraph mark) here:
The document is too large to save. - Microsoft Community It clears most options. |
#4
|
||||
|
||||
Why do you want a macro for what you can already do via Ctrl-h?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Use CSV as search criteria for Outlook search folder | lonesoac0 | Outlook | 0 | 03-07-2016 02:31 PM |
Filter Search Button | lonniepoet | Excel Programming | 53 | 12-23-2015 02:27 PM |
Onenote 2013 search is not identifying search terms correctly | Delta223 | OneNote | 0 | 08-12-2014 06:40 AM |
Search for date and then apply mutliple search criteria in huge dataset | maxtymo | Excel | 2 | 12-01-2013 04:52 AM |
Looking for Windows Search app with ability to search by content | gopher_everett | Office | 1 | 02-28-2013 09:23 PM |