![]() |
#4
|
||||
|
||||
![]()
It might be possible, provided all the text that you were looking for was formatted in the same way i.e if the text in column 1 of the table was formatted as 16 point bold Times New Roman, then that should be doable without the use of extra columns. Try the following (I have commented out the unnecessary lines):
Code:
Option Explicit Sub ReplaceFromTableWithFormatting() ' Slightly Tweaked from Graham Mayor's TableReplace Function ' And Doug Robbins ' Bulk Find & Replace From Table ' Dim oChanges As Document, oDoc As Document Dim oTable As Table Dim oRng As Range Dim rFindText As Range, rReplacement As Range Dim i As Long Dim sFname As String '==================DOCUMENT LOCATION sFname = "C:\Users\Desktop\TableReplace.docx" Set oDoc = ActiveDocument Set oChanges = Documents.Open(Filename:=sFname, Visible:=False) Set oTable = oChanges.Tables(1) For i = 1 To oTable.Rows.Count Set oRng = oDoc.Range Set rFindText = oTable.Cell(i, 1).Range rFindText.End = rFindText.End - 1 Set rReplacement = oTable.Cell(i, 2).Range rReplacement.End = rReplacement.End - 1 Selection.HomeKey wdStory With oRng.Find ' Find only the exact formatted version as displayed in Column 1 '.Format = True ' This may not be correct? '.ClearFormatting '.Replacement.ClearFormatting 'set the variety of formats to look for .Font.Name = rFindText.Font.Name .Font.Bold = rFindText.Font.Bold .Font.Size = rFindText.Font.Size .Font.Italic = rFindText.Font.Italic .Font.Underline = rFindText.Font.Underline .Font.ColorIndex = rFindText.Font.ColorIndex Do While .Execute(FindText:=rFindText, _ MatchWholeWord:=True, _ MatchWildcards:=False, _ Forward:=True, _ Wrap:=wdFindStop) = True ' oRng.Select oRng.FormattedText = rReplacement.FormattedText oRng.Collapse wdCollapseEnd Loop End With Next i oChanges.Close wdDoNotSaveChanges End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jc491 | Word VBA | 8 | 09-30-2015 06:10 AM |
Macro to keep formatted form fields after mail merge or replace text with formatted form fields | jer85 | Word VBA | 2 | 04-05-2015 10:00 PM |
![]() |
WaltR | Word | 2 | 10-11-2014 03:16 PM |
Word VBA Find Table Text Shading Colour and replace with another | QA_Compliance_Advisor | Word VBA | 10 | 09-19-2014 08:36 AM |
![]() |
bennymc | Word VBA | 1 | 01-27-2014 04:23 PM |