A
Ann Scharpf
My company recently completely overhauled a fairly large
software system. As part of the upgrade, all the fields
were renamed with a new naming convention. Now we must
update the documentation with the new names.
There are approximately 500 files and about 4,850
replacement terms for the old field names. I'd like to
create a table with old and new terms and have a macro
parse the table and do the replacements.
I originally posted this question on the Word page. Greg
Maxey helped me out by giving me the following VBA macro.
This macro works on one file at a time. I created a small
table and did a test and it works fine.
My question is ... how many search & replace rows can I
safely have in a table? I.e. how many replace functions
can I have Word do without blowing up? I'm sure I can't
include all the 4,850 replaces in a single macro but I'd
like to divide it up into the fewest number of macros
possible, since we have to run the macros on 500 files.
(I don't know VBA and don't know how to marry up this
macro with some macros that have been posted for searching
& replacing across all the files in a folder.)
Our word processing team is working on computers that
still have Word 97 and Word 2000 on them. Operating
system is Windows 2000. Their machines have 130 MB RAM.
Here is the macro. Thanks for any advice you can give me.
Ann Scharpf
_______________________________
Sub TechRef_S_R()
'
' TechRef_S_R Macro
' Macro created 06/16/04 by ANN.SCHARPF
'
'
'
Dim WordList As Document
Dim Source As Document
Dim i As Integer
Dim Find As Range
Dim Replace As Range
Set Source = ActiveDocument
' Change the path and filename in the following to suit
where you have your list of words
Set WordList = Documents.Open
(FileName:="C:\TechRef\SRlist.doc")
Source.Activate
For i = 2 To WordList.Tables(1).Rows.Count
Set Find = WordList.Tables(1).Cell(i, 1).Range
Find.End = Find.End - 1
Set Replace = WordList.Tables(1).Cell(i, 2).Range
Replace.End = Replace.End - 1
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Find
.Replacement.Text = Replace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
End Sub
software system. As part of the upgrade, all the fields
were renamed with a new naming convention. Now we must
update the documentation with the new names.
There are approximately 500 files and about 4,850
replacement terms for the old field names. I'd like to
create a table with old and new terms and have a macro
parse the table and do the replacements.
I originally posted this question on the Word page. Greg
Maxey helped me out by giving me the following VBA macro.
This macro works on one file at a time. I created a small
table and did a test and it works fine.
My question is ... how many search & replace rows can I
safely have in a table? I.e. how many replace functions
can I have Word do without blowing up? I'm sure I can't
include all the 4,850 replaces in a single macro but I'd
like to divide it up into the fewest number of macros
possible, since we have to run the macros on 500 files.
(I don't know VBA and don't know how to marry up this
macro with some macros that have been posted for searching
& replacing across all the files in a folder.)
Our word processing team is working on computers that
still have Word 97 and Word 2000 on them. Operating
system is Windows 2000. Their machines have 130 MB RAM.
Here is the macro. Thanks for any advice you can give me.
Ann Scharpf
_______________________________
Sub TechRef_S_R()
'
' TechRef_S_R Macro
' Macro created 06/16/04 by ANN.SCHARPF
'
'
'
Dim WordList As Document
Dim Source As Document
Dim i As Integer
Dim Find As Range
Dim Replace As Range
Set Source = ActiveDocument
' Change the path and filename in the following to suit
where you have your list of words
Set WordList = Documents.Open
(FileName:="C:\TechRef\SRlist.doc")
Source.Activate
For i = 2 To WordList.Tables(1).Rows.Count
Set Find = WordList.Tables(1).Cell(i, 1).Range
Find.End = Find.End - 1
Set Replace = WordList.Tables(1).Cell(i, 2).Range
Replace.End = Replace.End - 1
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Find
.Replacement.Text = Replace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
End Sub