![]() |
|
#2
|
||||
|
||||
|
Without the tables, it is impossible to test against what you have, but the following should be close
Code:
Option Explicit
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 22 Jul 2017
Const myKeyTerms As String = _
"Aerospace, Space & Defence"
Dim oDoc As Document
Dim oTarget As Document
Dim oTable As Table
Dim oRng As Range
Dim oNew As Range
Dim oCell As Cell
Set oDoc = ActiveDocument
Set oTarget = Documents.Add
oTarget.Range.Text = myKeyTerms & vbCr
oTarget.Paragraphs(1).Range.Font.Bold = True
If oDoc.Tables.Count = 0 Then
MsgBox "No tables in this document?"
GoTo lbl_Exit
End If
For Each oTable In oDoc.Tables
Set oRng = oTable.Range
With oRng.Find
Do While .Execute(FindText:=myKeyTerms)
If oRng.InRange(oTable.Range) Then
If oRng.Font.Bold = True Then
oRng.Start = oRng.Rows(1).Range.Next.Rows(1).Range.Start
oRng.End = oTable.Range.End
For Each oCell In oRng.Cells
If oCell.Range.Font.Bold = True Then
oRng.End = oCell.Range.Start
Exit For
End If
Next oCell
Exit Do
End If
End If
oRng.Collapse 0
Loop
End With
Set oNew = oTarget.Range
oNew.Collapse 0
oNew.FormattedText = oRng.FormattedText
Next oTable
lbl_Exit:
Set oDoc = Nothing
Set oTarget = Nothing
Set oRng = Nothing
Set oNew = Nothing
Set oTable = Nothing
Set oCell = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find and replace headings in bold and underline
|
redzan | Word VBA | 4 | 02-13-2016 12:24 PM |
Find, select, and replace part of text with bold
|
paik1002 | Word VBA | 4 | 12-07-2015 11:24 PM |
VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color
|
jc491 | Word VBA | 8 | 09-30-2015 06:10 AM |
find and replace in bold
|
redzan | Word VBA | 1 | 07-27-2014 03:35 PM |
Word VBA Macro to Find and Replace based on the Alt Text of an Image
|
bennymc | Word VBA | 1 | 01-27-2014 04:23 PM |