Microsoft Office Forums How to point a macro that highlights from a string of words at the footnotes rather than main doc

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2019, 07:34 AM
poggyton poggyton is offline How to point a macro that highlights from a string of words at the footnotes rather than main doc Windows 10 How to point a macro that highlights from a string of words at the footnotes rather than main doc Office 2016
Novice
How to point a macro that highlights from a string of words at the footnotes rather than main doc
 
Join Date: Oct 2019
Posts: 3
poggyton is on a distinguished road
Default How to point a macro that highlights from a string of words at the footnotes rather than main doc

I came across most of a solution to what I am trying to accomplish in this thread https://www.msofficeforums.com/word-...-document.html

Quote:
Originally Posted by macropod View Post
Hi AtaLoss,

Try something based on:
Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "dog,cat,pig,horse,man"
For i = 0 To UBound(Split(StrFnd, ","))
  Set Rng = ActiveDocument.Range
  With Rng.Find
    .ClearFormatting
    .Text = Split(StrFnd, ",")(i)
    .Replacement.ClearFormatting
    .Replacement.Highlight = True
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
    .Execute Replace:=wdReplaceAll
  End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Note: Because I've set 'MatchAllWordForms = True', a Find for 'cat' or 'man' will also find & highlight 'cats' & 'men'. Apart from that, the matched words must be whole words. That means you don't need multiple expressions to capture the various forms of a given word.
The only problem I'm having is that this only highlights above the line text, not text within footnotes. I would prefer if it it only searched footnotes, but all text could also work. From my brief research I believe this has to do with the range being set, and I've been noodling around with the "Footnotes" object to try to change this with no success.



Thank you,

Poggyton
Reply With Quote
  #2  
Old 10-02-2019, 11:12 AM
gmaxey gmaxey is offline How to point a macro that highlights from a string of words at the footnotes rather than main doc Windows 10 How to point a macro that highlights from a string of words at the footnotes rather than main doc Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 966
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "dog,cat,pig,horse,man"
For i = 0 To UBound(Split(StrFnd, ","))
  Set Rng = ActiveDocument.StoryRanges(wdFootnotesStory)
  With Rng.Find
    .ClearFormatting
    .Text = Split(StrFnd, ",")(i)
    .Replacement.ClearFormatting
    .Replacement.Highlight = True
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
    .Execute Replace:=wdReplaceAll
  End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-02-2019, 12:03 PM
poggyton poggyton is offline How to point a macro that highlights from a string of words at the footnotes rather than main doc Windows 10 How to point a macro that highlights from a string of words at the footnotes rather than main doc Office 2016
Novice
How to point a macro that highlights from a string of words at the footnotes rather than main doc
 
Join Date: Oct 2019
Posts: 3
poggyton is on a distinguished road
Thumbs up

Quote:
Originally Posted by gmaxey View Post
Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "dog,cat,pig,horse,man"
For i = 0 To UBound(Split(StrFnd, ","))
  Set Rng = ActiveDocument.StoryRanges(wdFootnotesStory)
  With Rng.Find
    .ClearFormatting
    .Text = Split(StrFnd, ",")(i)
    .Replacement.ClearFormatting
    .Replacement.Highlight = True
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
    .Execute Replace:=wdReplaceAll
  End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
That's awesome, thank you so much! I really appreciate it
Reply With Quote
  #4  
Old 10-04-2019, 02:29 PM
gmaxey gmaxey is offline How to point a macro that highlights from a string of words at the footnotes rather than main doc Windows 10 How to point a macro that highlights from a string of words at the footnotes rather than main doc Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 966
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

my pleasure. You're welcome
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 10-15-2019, 06:19 PM
poggyton poggyton is offline How to point a macro that highlights from a string of words at the footnotes rather than main doc Windows 10 How to point a macro that highlights from a string of words at the footnotes rather than main doc Office 2016
Novice
How to point a macro that highlights from a string of words at the footnotes rather than main doc
 
Join Date: Oct 2019
Posts: 3
poggyton is on a distinguished road
Default

Hey, followup question if you could. I finally got my full string of words ready to go (900) when I learn that there is a line length limit with no wordwrap in VBA, and you cant _split in the middle of a string.

How would one add an additional terms? Is there a section I can just copy paste?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to point a macro that highlights from a string of words at the footnotes rather than main doc Looking for certain words in a string Guinness Excel 13 08-09-2019 08:50 AM
Word VBA_find string against bullet point Mahesh Word VBA 2 01-19-2018 03:27 AM
How to point a macro that highlights from a string of words at the footnotes rather than main doc Adding spaces only between each main bullet point dylansmith Word 2 09-02-2015 05:14 AM
Can you align the starting point of footnotes in multi-column format? New Daddy Word 1 11-10-2012 01:54 AM
How to make words hot and point to a web address? jlp Word 2 05-27-2012 01:58 PM


All times are GMT -7. The time now is 06:14 PM.


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