#1
|
|||
|
|||
Need VBA code for find and replace between two files
Hi Paul,
I need the VBA code to find and replace between the two word files. File 1: have the content like as follows, <desc>abcv</desc> <desc>efgh</desc> <desc>tdvg</desc> <desc>aere</desc> etc.... File 2: have the tags like <desc></desc> in several places between the texts. I want to copy the tag with texts from File 1 and replace in to the File 2 vise vara which means find first item in File 2 and replace first item from File 1. So 200 items to be find and copy from File 1 and replace the same 200 items in to the File 2. Please let me know the code? Note: The VBscript code is acceptable in Notepad++. So if you provide the VBS it will more helpful. Thanks ganesang |
#2
|
||||
|
||||
For what you've described, that's as simple as:
Code:
Sub BulkFindReplace() Application.ScreenUpdating = False Dim FRDoc As Document, FRList, i As Long 'Load the strings from the reference doc into a text string to be used as an array. Set FRDoc = Documents.Open("Drive:\FilePath\FindReplaceList.doc", ReadOnly:=True, Addtorecentfiles:=False, Visible:=False) FRList = FRDoc.Range.Text FRDoc.Close False Set FRDoc = Nothing With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Text = "<desc></desc>" .Forward = True 'Process each entry from the source list. For i = 0 To UBound(Split(FRList, vbCr)) - 1 .Replacement.Text = Split(FRList, vbCr)(i) .Execute Replace:=wdReplaceOne Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks Paul!
I will check that code |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find & Replace in Header/Footer in 1000 files | amodiammmuneerk@glenmarkp | Word | 12 | 03-05-2018 03:31 AM |
Code to find numerical string + space throughout document & replace them with Comma | Robert Kay | Word VBA | 6 | 02-21-2018 04:41 PM |
Find & Replace text in Field Code across multiple documents | RPM7 | Word VBA | 6 | 05-12-2017 12:58 AM |
Macro code that prompts user to enter text, then does find/replace. | sfvegas | PowerPoint | 0 | 01-10-2016 08:02 PM |
Looking for code to create a macro that prompts user to enter text, then does a find/replace. | sfvegas | PowerPoint | 0 | 01-08-2016 02:22 AM |