systemssupply
asked on
MS Word Macro to Highlight Text
Hi,
I need to write a macro or other code to achieve the following goal when a document is opened.
1) Display the word document
2) Highlight any words in the document which are in the clipboard.
The request sound simple enough but thus far I am stumped as how to approach this.
Here is a samle of the clipboard contents:
Index of INC_DOCS - telephone and perry
P:\PUBLIC\INC_DOCS\86804.d oc 6 Hits
P:\PUBLIC\INC_DOCS\36905.d oc 4 Hits
P:\PUBLIC\INC_DOCS\97053.d oc 3 Hits
P:\PUBLIC\INC_DOCS\86083.d oc 2 Hits
P:\PUBLIC\INC_DOCS\53412.d oc 2 Hits
P:\PUBLIC\INC_DOCS\62894.d oc 2 Hits
P:\PUBLIC\INC_DOCS\93763.d oc 3 Hits
P:\PUBLIC\INC_DOCS\46199.d oc 3 Hits
P:\PUBLIC\INC_DOCS\80905.d oc 2 Hits
P:\PUBLIC\INC_DOCS\90660.d oc 3 Hits
P:\PUBLIC\INC_DOCS\97363.d oc 3 Hits
P:\PUBLIC\INC_DOCS\85723.d oc 7 Hits
P:\PUBLIC\INC_DOCS\96224.d oc 3 Hits
P:\PUBLIC\INC_DOCS\85723.r tf 4 Hits
P:\PUBLIC\INC_DOCS\86177.d oc 2 Hits
P:\PUBLIC\INC_DOCS\76956.d oc 2 Hits
P:\PUBLIC\INC_DOCS\83505.d oc 2 Hits
P:\PUBLIC\INC_DOCS\91948.d oc 3 Hits
P:\PUBLIC\INC_DOCS\94205.d oc 2 Hits
P:\PUBLIC\INC_DOCS\96517.d oc 2 Hits
I need to write a macro or other code to achieve the following goal when a document is opened.
1) Display the word document
2) Highlight any words in the document which are in the clipboard.
The request sound simple enough but thus far I am stumped as how to approach this.
Here is a samle of the clipboard contents:
Index of INC_DOCS - telephone and perry
P:\PUBLIC\INC_DOCS\86804.d
P:\PUBLIC\INC_DOCS\36905.d
P:\PUBLIC\INC_DOCS\97053.d
P:\PUBLIC\INC_DOCS\86083.d
P:\PUBLIC\INC_DOCS\53412.d
P:\PUBLIC\INC_DOCS\62894.d
P:\PUBLIC\INC_DOCS\93763.d
P:\PUBLIC\INC_DOCS\46199.d
P:\PUBLIC\INC_DOCS\80905.d
P:\PUBLIC\INC_DOCS\90660.d
P:\PUBLIC\INC_DOCS\97363.d
P:\PUBLIC\INC_DOCS\85723.d
P:\PUBLIC\INC_DOCS\96224.d
P:\PUBLIC\INC_DOCS\85723.r
P:\PUBLIC\INC_DOCS\86177.d
P:\PUBLIC\INC_DOCS\76956.d
P:\PUBLIC\INC_DOCS\83505.d
P:\PUBLIC\INC_DOCS\91948.d
P:\PUBLIC\INC_DOCS\94205.d
P:\PUBLIC\INC_DOCS\96517.d
ASKER
That sound logical but raises another question. In my example "Index of INC_DOCS - telephone and perry "
If I run a find and replace the whole string will not be in the document. Rather, the words telephone, perry will be in the document.
How can I tell the find / replace to search for any of the words not the whole string?
If I run a find and replace the whole string will not be in the document. Rather, the words telephone, perry will be in the document.
How can I tell the find / replace to search for any of the words not the whole string?
I'm not quite sure that I understand the problem, but you if you want to find one or another of two words, you can do two successive searches.
ASKER
True, I could run two searches however, in my example I had two words in a boolean search setup. It could also be additional words. I think that I need to find a way to export these terms into some sort of array to search on.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Then I would take each line and do a Find and Replace in the original document, the Replace to apply a highlighting colour to anything found.