vba - Highlight list words in a MS Word file -


first want don't know vba , want highlight list words in a.txt(or .doc) file to ms-word file b.docx full of texts. found vba code works fine needs put words code strfnd = "dog,cat,pig,horse,man". can me change somehow code gets list words file a.txt instead of typing these words. thank much.

sub hilightlist()  application.screenupdating = false  dim strfnd string, rng range, long  strfnd = "dog,cat,pig,horse,man"  = 0 ubound(split(strfnd, ","))    set rng = activedocument.range    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  next  set rng = nothing  application.screenupdating = true  end sub

ok, @ first document list of words, highlight same words in current document.

sub comparewordlist()   dim scheckdoc string   dim docref document   dim doccurrent document   dim wrdref object  scheckdoc = "c:\highlight\a.txt" set doccurrent = selection.document set docref = documents.open(scheckdoc) doccurrent.activate  selection.find     .clearformatting     .replacement.clearformatting     .replacement.font.bold = true     .replacement.text = "^&"     .forward = true     .format = true     .matchwholeword = true     .matchcase = true     .matchwildcards = false end  each wrdref in docref.words     if asc(left(wrdref, 1)) > 32         selection.find             .wrap = wdfindcontinue             .text = wrdref             .execute replace:=wdreplaceall         end     end if next wrdref  docref.close doccurrent.activate end sub 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -