PDA

View Full Version : Solved: How to read Excel or Word file (multi-word phrases) into Array



pradeepdeepu
01-13-2013, 11:05 PM
Hi,

I'm using the below code to highlight multi-word phrases in a word document.

This code is working fine for me, but i have more than 500 multi-words to update in array, which i feel is more time consuming and i am uncomfortable adding new multi-word to the array list - whenever i need to.

So is it possible to update all the multi-word phrases or words in an excel or a word document and refer that file to this code to find multi-word and highlight/format.


Dim oRng As Word.Range
Dim arrWords
Dim i As Long

arrWords = Array("I think that", "24-hr", "keep and immaculate")

For i = 0 To UBound(arrWords)
Set oRng = ActiveDocument.Range

With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = arrWords(i)
.MatchWholeWord = True
.Replacement.Font.Underline = True
.Replacement.Font.TextColor = wdColorBlue
.Replacement.Font.Italic = True
.Execute Replace:=wdReplaceAll
End With
Next


Can anyone pls help me on this.

Thanks in Advance

snb
01-14-2013, 02:12 AM
you can use a list in a Word document: each paragraph contains the word combination you are looking for.


for each it in split(documents("list.doc").content,vbcr)
.text=it
.replacement.text=it
next

pradeepdeepu
01-14-2013, 04:49 AM
SNB,
Thanks for your response.

I am a newbie to VBA, so can u pls help me where to update the code you have provided.