Proofreading macro

  • Thread starter Thread starter Grey Old Man
  • Start date Start date
G

Grey Old Man

I am looking for help to write a macro that will proofread a series of large
documents for me.

A text file will be used for all suggested replacements. For example:

phone=telephone
fax=facsimile
&=and
24 x 7=24x7
7 x 24=24x7
mgmt=management

The macro will read the text file and find and replace as appropriate.
Track changes must be switched on at the start and switched off at the end
of the routine.

The reason for using a text file is for simplicity and easy maintenance
without knowledge of VBA code. Thanks in anticipation.
 
You cannot 'proof read' a document with a macro. You can however use a macro
to perform a series of pre-defined replacements, such as those you have
suggested.

Save the list as a two column table. If you already have the list in the
format shown, open the list in Word and convert the text to a two column
table split at the = sign. then run the following macro. You need to bear in
mind that the searches will follow the order in the table and will complete
without prompting.


Sub ReplaceFromTableList()
Dim ChangeDoc As Document, RefDoc As Document
Dim cTable As Table
Dim oFind As Range, oReplace As Range
Dim i As Long
Dim sFname As String
'Change the path to reflect where you have saved the table document.
sFname = "D:\My Documents\Word Documents\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 oFind = cTable.Cell(i, 1).Range
oFind.End = oFind.End - 1
Set oReplace = cTable.Cell(i, 2).Range
oReplace.End = oReplace.End - 1
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFind, _
ReplaceWith:=oReplace, _
Replace:=wdReplaceAll, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub
http://www.gmayor.com/installing_macro.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
If you had the words to be replaced in column 1 of a table in a Word
document, starting in row 2 and the replacement words in column 2 of the
same table, and you save and close that document and open it when asked to
do so. The following macro run when the document in which you want the
replacements to be made is the active document should do what you want:

Dim i As Long
Dim rngFind As Range
Dim rngReplace As Range
Dim Source As Document
Dim Target As Document
Set Target = ActiveDocument
Target.TrackRevisions = True
With Dialogs(wdDialogFileOpen)
.Show
End With
Set Source = ActiveDocument
With Source.Tables(1)
For i = 2 To .Rows.Count
Set rngFind = .Cell(i, 1).Range
rngFind.End = rngFind.End - 1
Set rngReplace = .Cell(i, 2).Range
rngReplace.End = rngReplace.End - 1
With Target
.TrackRevisions = True
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=rngFind.Text, Forward:=True, _
MatchWildcards:=False, Replacewith:=rngReplace.Text, _
Wrap:=wdFindContinue, MatchCase:=False) = True
Loop
End With
End With
Next i
End With
Source.Close wdDoNotSaveChanges
Target.TrackRevisions = False




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Back
Top