Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2020, 06:40 PM
bscott221 bscott221 is offline Search Button Windows 10 Search Button Office 2019
Novice
Search Button
 
Join Date: Jun 2020
Posts: 1
bscott221 is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 06-01-2020, 07:05 PM
Guessed's Avatar
Guessed Guessed is offline Search Button Windows 10 Search Button Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 06-02-2020, 09:20 AM
Charles Kenyon Charles Kenyon is online now Search Button Windows 10 Search Button Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #4  
Old 06-02-2020, 03:25 PM
macropod's Avatar
macropod macropod is offline Search Button Windows 7 64bit Search Button Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by bscott221 View Post
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.
Why do you want a macro for what you can already do via Ctrl-h?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft