#1
|
|||
|
|||
seach an Excel list elements in word document
Hi everybody,
I am looking to build a macro or prog. to search and highlight multiple words in a document. (my list to search is in an excel doc but I can copy it in a word doc) example: find "Alex" and "car" and "15822" etc. in one hundred pages text. Thank you in advance |
#2
|
||||
|
||||
Hi 7ajar,
You could use a macro like: Code:
Sub Demo() Dim arrWords, i As Long Application.ScreenUpdating = False arrWords = Array("Alex", "car", "15822") With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .MatchWholeWord = True .Replacement.Text = "^&" .Replacement.Highlight = True For i = 0 To UBound(arrWords) .Text = arrWords(i) .Execute Replace:=wdReplaceAll Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you Macropod,
This is great, it work perfectly. However, I have a long list witch I will regularly update. It will be excellent if I can pinpoint directly the list and not update it manually in the macro! Thank you one more time |
#4
|
|||
|
|||
dynamise the macro
To be make the macro dynamic, I would like to replace :
ArrWords= array ("Alex", "car", 15822") by the the elements of A2:A1000 cells in sheet3 of my excel document: C:\Users\ajar\Desktop\list.xls Thank you in advance |
#5
|
||||
|
||||
Hi 7ajar,
Any particular reason for maintaining the list in Excel, rather than in another Word document (or even a plain text file)? Whilst retrieving the data from Excel isn't particularly difficult, it adds overheads that can be avoided in the data are in another Word document (or a plain text file). For an example of reading in a list from another document, see my code at: http://www.vbaexpress.com/forum/showthread.php?t=34992
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 02-26-2011 at 12:49 AM. Reason: Added link to code for reading list from another document. |
#6
|
|||
|
|||
Thank you very much Macropod!
It works perfectly Thank you again |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Embedding Excel Object in Word Document Failing | brandonf | Word | 0 | 10-04-2010 11:45 AM |
MS Word to pdf - elements moved | SFC | Word | 1 | 05-25-2010 11:27 AM |
C# API to identify the uncommitted changes in Excel and Word document? | althafuddeen | Excel | 0 | 04-06-2010 07:40 AM |
Exporting word document to Excel | scaifea | Word | 1 | 01-09-2010 10:57 AM |
Connecting word and excel document | jmarin | Word | 0 | 11-28-2008 02:55 AM |