a small change to a macro needed

W

wzrokowiec

Hello
Two years ago Mr Graham Mayor helped me a lot with writing a macro in Microsof
Visual Basic 6.3 that I've been using till now but I need a small modification
The macro works as follows
it searches through a tekst in an open Word document, finds a string o
characters that is given in a table in a separate file and changes string
foun
in one column to those in the second column
Now I need a small improvement: it should mark with red font color the whol
paragraphs it DOES NOT change. That's all. I'm quoting the macro and need som
help with adding this function

Sub correction(
Dim oChanges As Document, oDoc As Documen
Dim oTable As Tabl
Dim oRng As Rang
Dim rFindText As Range, rReplacement As Rang
Dim i As Lon
Dim sFname As Strin
'************************************
sFname = "C:corrections.doc
'************************************
Set oDoc = ActiveDocumen
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False
Set oTable = oChanges.Tables(1
For i = 1 To oTable.Rows.Coun
Set oRng = oDoc.Rang
Set rFindText = oTable.Cell(i, 1).Rang
rFindText.End = rFindText.End -
Set rReplacement = oTable.Cell(i, 2).Rang
rReplacement.End = rReplacement.End -
With oRng.Fin
.ClearFormattin
.Replacement.ClearFormattin
Do While .Execute(findText:=rFindText,
MatchWholeWord:=True,
MatchWildcards:=False,
Forward:=True,
Wrap:=wdFindContinue) = Tru
oRng.Text = rReplacemen
Loo
End Wit
Next
oChanges.Close wdDoNotSaveChange
End Su

Thank yo
wZrokowiec
 
B

Barry Schwarz

I'm not that good with macros but wouldn't it be easier to change
everything to red to start with and then after each substitution
change that individual paragraph back to black?
 
W

wzrokowiec

Barry Schwarz wrote on 01/18/2013 13:12 ET
I'm not that good with macros but wouldn't it be easier to chang
everything to red to start with and then after each substitutio
change that individual paragraph back to black

On Fri, 18 Jan 2013 09:23:34 -0600, wzrokowie
wrote

Remove del for emai
Yes, it can be done the other way round. First I change the whole text to re
font color manually and than I run the macro. The point is, however, that stil
I need some help with changing to black font color (this time ) the whol
paragraphs that the macro changes
What is important is the fact that the macro changes only particular words in
given paragraph (wich is good) but at the end I'd like to see which paragraph
where changed and which not

Have a good da
wZrokowiec
 
E

Ed Weber

Try this to see if it does what you want. I have added two lines of code.

Sub correction()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
'*************************************
sFname = "C:corrections.doc"
'*************************************
Set oDoc = ActiveDocument
oDoc.Range.Font.ColorIndex = wdRed
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
Set oRng = oDoc.Range
Set rFindText = oTable.Cell(i, 1).Range
rFindText.End = rFindText.End - 1
Set rReplacement = oTable.Cell(i, 2).Range
rReplacement.End = rReplacement.End - 1
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=rFindText, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue) = True
oRng.Text = rReplacement
oRng.Paragraphs(1).Range.Font.ColorIndex = wdAuto
Loop
End With
Next i
oChanges.Close wdDoNotSaveChanges
End Sub

--


wzrokowiec said:
Hello,
Two years ago Mr Graham Mayor helped me a lot with writing a macro in
Microsoft
Visual Basic 6.3 that I've been using till now but I need a small
modification.
The macro works as follows:
it searches through a tekst in an open Word document, finds a string of
characters that is given in a table in a separate file and changes strings
found
in one column to those in the second column.
Now I need a small improvement: it should mark with red font color the
whole
paragraphs it DOES NOT change. That's all. I'm quoting the macro and need
some
help with adding this function.

Sub correction()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
'*************************************
sFname = "C:corrections.doc"
'*************************************
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
Set oRng = oDoc.Range
Set rFindText = oTable.Cell(i, 1).Range
rFindText.End = rFindText.End - 1
Set rReplacement = oTable.Cell(i, 2).Range
rReplacement.End = rReplacement.End - 1
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=rFindText, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue) = True
oRng.Text = rReplacement
Loop
End With
Next i
oChanges.Close wdDoNotSaveChanges
End Sub

Thank you
wZrokowiec




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 130119-0, 01/19/2013
Tested on: 1/19/2013 9:12:25 AM
avast! - copyright (c) 1988-2013 AVAST Software.
http://www.avast.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top