![]() |
|
#1
|
||||
|
||||
|
Hello to all,
this Tuesday. I hope every one is doing great today! ![]() Thank you for all the help provided these previous past few days. I have been using Graham's fantastic Replace from Table VBA Macro. The code below - does a fantastic job. It searches and replaces all the text in column 1 - and replaces with text found in column 2. I was hoping to simply extend the code. I don't know if what I am asking for is possible? As I have been fiddling about with it and have not been able to make heads or tails with the solution, nothing happens when I add new code on to it. No doubt - I am doing it wrong ![]() Is it possible to find the exact formatted text in column A of the table, ignoring all other types of formatting Here is an example http://tinypic.com/r/258cyf6/9 Code:
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
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
I will not lie this is a complex task, what seems simple enough in theory is not when it comes to coding. ![]() Thank you so very much for taking the time to look over this. I really really do appreciate all the help from the great individuals here ![]() I would be lost without the kind help thank you J |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
| 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 |
How can I paste text that's not formatted as a table into a new table?
|
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 |
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 |