![]() |
|
|
|
#1
|
|||
|
|||
|
Hello Everybody.
I have a code able to highlight all the words in the string keywords = "if,then,from,to,all,first,between,first,last, of); and start a new line for each one.My request here is: first, my list is really long -SO- how can I break it or separated in different lines. Second: how to replace each word in the list for different replacement for each one. This is the code I have: Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim keywords As String, Rng As Range, i As Long
keywords = "if,then,from,to,all,first,between,first,last,of,and,or,print,find,swap,check,print,count,when,require,do not,with,but, rather than,where,is not,as,in,an,is,by,are,on,for,because,some,before,after,also,under,inside,around,into,next to,often,let,delete,copy,find,calculate,check,print,until,was,were,behind,had been"
For i = 0 To UBound(Split(keywords, ","))
Set Rng = ActiveDocument.Range
With Rng.Find
.ClearFormatting
.Text = Split(keywords, ",")(i)
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Replacement.Text = "^l^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
|
|
#2
|
||||
|
||||
|
You could use something like:
Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, StrRep As String, i As Long
StrFnd = "if,then,from,to,all,first,between,first,last,of,and,or,print,find,swap," & _
"check,print,count,when,require,do not,with,but,rather than,where,is not,as,in,an," & _
"is,by,are,on,for,because,some,before,after,also,under,inside,around,into,next to," & _
"often,let,delete,copy,find,calculate,check,print,until,was,were,behind,had been"
StrRep = "if,then,from,to,all,first,between,first,last,of,and,or,print,find,swap," & _
"check,print,count,when,require,do not,with,but,rather than,where,is not,as,in,an," & _
"is,by,are,on,for,because,some,before,after,also,under,inside,around,into,next to," & _
"often,let,delete,copy,find,calculate,check,print,until,was,were,behind,had been"
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Format = True
.Forward = True
.MatchCase = False
.MatchWholeWord = True
.Wrap = wdFindContinue
For i = 0 To UBound(Split(StrFnd, ","))
.Text = Split(StrFnd, ",")(i)
.Replacement.Text = "^l" & Split(StrRep, ",")(i)
.Execute Replace:=wdReplaceAll
Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thank you for your Answer.
I didn't got, for example how I will replace each word: example print replace for method, if for selection and so on. Thank you so much Paul for the time you spend helping me. |
|
#4
|
||||
|
||||
|
Quote:
PS: you have three 'print' entries in your list...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
work perfect thank you so much
|
|
| Tags |
| vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Wildcard replace any string in context with a specified string
|
wardw | Word | 7 | 05-07-2018 09:13 AM |
How can I compare a string in a cell to another string?
|
Amitti | Word VBA | 2 | 04-10-2017 07:35 PM |
| How to find all string within string. | PRA007 | Word VBA | 18 | 02-12-2016 08:11 PM |
Word Replacement Option
|
mattyra | Word | 7 | 02-11-2015 11:13 PM |
Way to search for a string in text file, pull out everything until another string?
|
omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |