Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
jvr jvr is offline
external usenet poster
 
Posts: 1
Default How to replace multiple words with replacement words in Excel

How to replace multiple words with replacement words in Excel


In my Word documents, I must use temporary €śIdentifiers€ť (internal temporary
codes; supplied to me) that must be later replaced with actual €śIdentifiers€ť
(in an Excel file supplied by the customer much later and perhaps multiple
times).

The actual €śIdentifiers€ť in the Excel file are €śpaired€ť with my temporary
€śIdentifiers€ť (as two cells, side-by-side).

For example:
PTT-001 205-PTT-0924
PTT-124 205-PTT-0020
Meaning:
For each instance of PTT-001 replace with 205-PTT-0924,
for each instance of PTT-124 replace with 205-PTT-0020,
etc. (there may or may not be any particular pattern).

There will be hundreds of these €śpairs€ť and each one may be in the document
zero, one, or more times.

Doing this manually with €śFind and Replace€ť is extremely time-consuming.

Thanks so much in advance for any solution.

I really appreciate it.




  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to replace multiple words with replacement words in Excel

If you copy the two columns of the Excel table to Word, and save it as a
Word document, with its path identified in place of "D:\My
Documents\Test\changes.doc" in the line:-

sFname = "D:\My Documents\Test\changes.doc"

the following macro run on your document will replace all the items in the
first column with the corresponding items in the second column

Sub ReplaceFromTableList()

Dim ChangeDoc As Document, RefDoc As Document
Dim cTable As Table
Dim oldPart As Range, newPart As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\changes.doc"
Set RefDoc = ActiveDocument
Set ChangeDoc = Documents.Open(sFname)
Set cTable = ChangeDoc.Tables(1)
RefDoc.Activate
For i = 1 To cTable.Rows.Count
Set oldPart = cTable.Cell(i, 1).Range
oldPart.End = oldPart.End - 1
Set newPart = cTable.Cell(i, 2).Range
newPart.End = newPart.End - 1
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oldPart, _
ReplaceWith:=newPart, _
Replace:=wdReplaceAll, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




jvr wrote:
How to replace multiple words with replacement words in Excel


In my Word documents, I must use temporary "Identifiers" (internal
temporary codes; supplied to me) that must be later replaced with
actual "Identifiers" (in an Excel file supplied by the customer much
later and perhaps multiple times).

The actual "Identifiers" in the Excel file are "paired" with my
temporary "Identifiers" (as two cells, side-by-side).

For example:
PTT-001 205-PTT-0924
PTT-124 205-PTT-0020
Meaning:
For each instance of PTT-001 replace with 205-PTT-0924,
for each instance of PTT-124 replace with 205-PTT-0020,
etc. (there may or may not be any particular pattern).

There will be hundreds of these "pairs" and each one may be in the
document zero, one, or more times.

Doing this manually with "Find and Replace" is extremely
time-consuming.

Thanks so much in advance for any solution.

I really appreciate it.





Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace all words that have a certain value in them, not just the value itself. El Capitán de las Albondigas Microsoft Word Help 1 September 30th 07 02:27 AM
Replace words written in upper case for words in lower case Denise Microsoft Word Help 1 July 2nd 07 04:51 PM
how do I replace certain words in Word document Ron Microsoft Word Help 2 April 4th 07 09:28 PM
Trying to replace words with fields using Find/Replace mbleyle Microsoft Word Help 2 March 29th 06 11:35 PM
Find/ Replace is auto-capping the words I want to replace with Graham Mayor Microsoft Word Help 8 January 27th 06 01:39 AM


All times are GMT +1. The time now is 04:20 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"