PDA

View Full Version : [SOLVED:] Searching All Table Values that exist in Document 1 and highlight them



Khanonline
09-22-2014, 03:44 AM
Dear All,

I am new to VBA. I need urgent help regarding the case.

My Question is; I have a file say Document1 having just 1 Table and I was to search all its values in another Document that is Document 2 and when the values of Document 1 was found in Document 2 then I want to highlight Them...


Can any body help???

Thanks
Regards
MR Khan

gmayor
09-22-2014, 07:41 AM
You need something like:


Sub Highlighting()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oCell As Cell
Dim oRng As Range
Dim rFindText As Range
Const sFname As String = "C:\Path\Table.docx" 'The document with the table
Set oDoc = ActiveDocument 'The document to check (already opened)
Set oChanges = Documents.Open(Filename:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For Each oCell In oTable.Range.Cells
If Len(oCell.Range) > 2 Then
Set oRng = oDoc.Range
Set rFindText = oCell.Range
rFindText.End = rFindText.End - 1
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(FindText:=rFindText, _
MatchWholeWord:=True) = True
oRng.HighlightColorIndex = wdBrightGreen
Loop
End With
End If
Next oCell
lbl_Exit:
oChanges.Close 0
Set oChanges = Nothing
Set oDoc = Nothing
Set oRng = Nothing
Set rFindText = Nothing
Exit Sub
End Sub

Khanonline
09-22-2014, 08:13 AM
Thanks alot. I tested it and it work perfectly fine......

Khanonline
10-20-2014, 10:27 AM
Hi buddy,


Is there any Macro that just Restructure following Table to Registration Fee, One Month, Two Month and Three Month??

There is something wrong with Table Structure and I want a macro that just reorder this Table into above mentioned order?


Thanks in advance.