Jonathan
Wed May 07 08:01:44 PDT 2008
Hi den
"dendenden" <dendenden@discussions.microsoft.com> wrote in message
news:728C3D8C-E6D1-448B-969E-2740E256FB7A@microsoft.com...
>
> Hello all this is my first post. I could do with your advice.
>
> I have a 20 similar documents which share many repeating comments of 1
> sentence long. I have to update these old comments with new edited
> comments.
>
> I have created a table with two columns, containing the old comments and
> the
> corresponding new comments that I have edited. I plan to make a macro in
> Msword to find and replace the old comments for new, then run the macro on
> all 20 documents.
The following article may help you
Find & ReplaceAll on a batch of documents in the same folder
http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm
>
> However the process of creating the macro in itself is likely to take
> considerable time due to the number of comments (approx 250- 500 in
> total).
>
> And here's the question: Is there a way to make the macro use the table to
> change the old comments for the new? Or is there an easier way to do this?
Yes. The simplest approach is probably to load all the table's contents into
an array. Something like this
Dim sText() as String
Dim iRow as Long
Dim iColumn as Long
With ActiveDocument.Tables(1)
ReDim sText(1 to .Rows.Count, 1 To .Columns.Count)
For iRow = 1 to .Rows.Count
For iColumn = 1 To .Columns.Count
sText(iRow, iColumn) = .Cell(iRow, iColumn).Range.Text
sText(iRow, iColumn) = Left$(sText(iRow, iColumn),
Len(sText(iRow, iColumn)) - 2)
Next iColumn
Next iRow
End With
Now, you have all the strings of the table neatly arranged in a (presumably
2-column) array. What you now do is open each file in turn and do a
find/replace on each string pair. Your macro should continue like this.
Dim oDoc as Document
Dim vFile as Variant
With Application.FileSearch
.Lookin = "C:\Test" 'put your folder here
.FileName = "*.doc"
If .Execute Then
For Each vFile in .FoundFiles
Set oDoc = Documents.Open(vFile)
With oDoc.Range.Find
.Format = False
For iRow = 1 to UBound(sText, 1)
.Text = sText(iRow, 1)
.Replacement.Text = sText(iRow, 2)
.Execute Replace:=wdReplaceAll
Next iRow
End With
oDoc.Save
oDoc.Close
Next vFile
End If
End With
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup