Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 05-06-2021, 02:10 PM
macropod's Avatar
macropod macropod is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Even the macro recorder would record the code you need...

Somewhat more sophisticated:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String
Options.DefaultHighlightColorIndex = wdYellow
StrFnd = InputBox("What is the text to highlight?")
If Trim(StrFnd) = "" Then Exit Sub
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Replacement.Highlight = True
  .Text = StrFnd
  .Replacement.Text = "^&"
  .Format = True
  .Forward = True
  .MatchCase = True
  .MatchWildcards = False
  .Wrap = wdFindContinue
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to create a user form and populate it with a field from the main document? NMGMarques Word 3 02-12-2020 06:08 PM
How to perform (Find in Main Document) with VBA Find currency amounts in Word doc, perform sum GWTJR Word VBA 3 10-15-2017 02:22 PM
Macro to find a word in first row of table and then perform two macros hmsrose Word VBA 5 01-30-2015 12:17 AM
Can Word highlight the same text in the Reviewing Pane as in the main document? wordistheword Word 4 09-09-2013 04:50 AM
Connecting documents to main document themangoagent Word 1 08-07-2009 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:23 AM.


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