|
-
Aug 14th, 2008, 10:35 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Finding occurences of a word in Microsoft Word
I use the following to find a word in a word document opened in a DSOFramer ActiveX control:
Code:
oDoc = ctl.ActiveDocument
oDoc.ActiveWindow.Selection.WholeStory()
oDoc.ActiveWindow.Selection.Find.ClearFormatting()
oDoc.ActiveWindow.Selection.Find.Replacement.ClearFormatting()
With oDoc.ActiveWindow.Selection.Find
.Text = "control"
.Forward = True
.Wrap = WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oDoc.ActiveWindow.Selection.Find.Execute()
The code finds and highlights the first occurence of the word "control" but ignores all of the other occurences.
What am I doing wrong ? I must be missing something easy.
-
Aug 14th, 2008, 10:48 AM
#2
Re: Finding occurences of a word in Microsoft Word
Leave your current code in place, but instead of doing the Selection.Find.Execute(), do a
Code:
Selection.Find.HitHighlight "control"
-
Aug 14th, 2008, 11:24 AM
#3
Re: Finding occurences of a word in Microsoft Word
If you Record a Macro it will usually show you the code office apps use to complete the desired task.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 14th, 2008, 11:51 AM
#4
Re: Finding occurences of a word in Microsoft Word
 Originally Posted by RobDog888
If you Record a Macro it will usually show you the code office apps use to complete the desired task.
That's the way I usually do it, but I had to figure out the HitHighlight because the recording didn't happen to catch that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|