Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2018, 04:23 AM
ganesang ganesang is offline Need VBA code for find and replace between two files Windows XP Need VBA code for find and replace between two files Office 2016
Competent Performer
Need VBA code for find and replace between two files
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Post 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
Reply With Quote
  #2  
Old 09-04-2018, 05:46 AM
macropod's Avatar
macropod macropod is offline Need VBA code for find and replace between two files Windows 7 64bit Need VBA code for find and replace between two files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 09-04-2018, 06:00 AM
ganesang ganesang is offline Need VBA code for find and replace between two files Windows XP Need VBA code for find and replace between two files Office 2016
Competent Performer
Need VBA code for find and replace between two files
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Thanks Paul!

I will check that code
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need VBA code for find and replace between two files Find & Replace in Header/Footer in 1000 files amodiammmuneerk@glenmarkp Word 12 03-05-2018 03:31 AM
Need VBA code for find and replace between two files Code to find numerical string + space throughout document & replace them with Comma Robert Kay Word VBA 6 02-21-2018 04:41 PM
Need VBA code for find and replace between two files 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:45 AM.


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