Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-05-2016, 11:36 AM
jc491's Avatar
jc491 jc491 is offline VBA Word - Find Formatted Text Version Only  - Replace From Table Windows 10 VBA Word - Find Formatted Text Version Only  - Replace From Table Office 2016
VBA Novice
VBA Word - Find Formatted Text Version Only  - Replace From Table
 
Join Date: Sep 2015
Location: UK
Posts: 55
jc491 is on a distinguished road
Default VBA Word - Find Formatted Text Version Only - Replace From Table

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
This table solution for me is such a great tool - if I could just abuse the kindness of an advanced practitioner to see if if it's possible to do the impossible (which it is to me at this moment) - that is find the exact formatted text.

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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word - Find Formatted Text Version Only  - Replace From Table 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
VBA Word - Find Formatted Text Version Only  - Replace From Table 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
VBA Word - Find Formatted Text Version Only  - Replace From Table 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft