Consulting

Results 1 to 3 of 3

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

  1. #1

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

    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.

    [vba]
    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
    [/vba]

    Can anyone pls help me on this.

    Thanks in Advance
    Last edited by pradeepdeepu; 01-14-2013 at 12:05 AM. Reason: For better understanding

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    you can use a list in a Word document: each paragraph contains the word combination you are looking for.

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

  3. #3
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •