Formatting the macros.

D

Designingsally

Hi
I was wondering if the macros can do this. I have code for find and replace.
The code works perfectly fine. But I want the way the output to be displayed
differently.

I want a dialog box it shd be divided into two parts. The top part of the
box should contain the sentence which has the mistaken[FIND WORD] word. The
mistaken word should displayed in green. The bottom part should have
suggestion words [REPLACE WORD].

Further the dialog box must YES , NO, AND IGNORE buttons. On clicking:
Yes- the word must be replaced
No- skip and go to next word
IGNORE- the checking shd get over.

ALL THIS SHD HAPPEN SEQUENTIALLY. If the are 2 different words eg, hi and
hello. When the macros encouter hi, change must occur.When the macros
encouter hello,change must occur. If the document has 10 hi's and 5 hello's.
Changes must occur as and when HI and HELLO occur. NOT change all 10 HI's at
one shot and then change all 5 HELLOS at one shot.
For example,

I have a pen. The pen is great. This pen is lovely. I like lovely things.

The code I got I have is
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "pen" 'the word to find
sRepText = "pencils" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "lovely" 'the word to find
sRepText = "bad" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend

It will be great if someone comes up with a solution.
Thanks for helping a novice.

Sally
 
P

Pesach Shelnitz

Hi Sally,

The following macro can do everything that you requested except color the
words. It is based on your code, but I introduced an array so that it
wouldn't be necessary to repeat the code for each FIND WORD/REPLACE WORD
pair. You can also easily add more pairs to the macro simply by adding them
to the array.

Sub PromptToReplace()

Dim orng As Range
Dim sRep As VbMsgBoxResult
Dim textArray As Variant
Dim i As Long

ReDim textArray(1 To 2, 1 To 2) As String
textArray(1, 1) = "pen"
textArray(1, 2) = "pencils"
textArray(2, 1) = "lovely"
textArray(2, 2) = "bad"
With Selection
For i = 1 To UBound(textArray, 1)
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=textArray(i, 1))
Set orng = Selection.Range
sRep = MsgBox("The incorrect word '" & _
textArray(i, 1) & _
"' was found in the following sentence:" _
& vbCrLf & orng.Sentences(1) & vbCrLf _
& vbCrLf & "Replace this word with '" & _
textArray(i, 2) & "'?", vbYesNoCancel)
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveStart Unit:=wdCharacter, Count:=1
If sRep = vbCancel Then
Exit Sub
ElseIf sRep = vbYes Then
orng.Text = textArray(i, 2)
End If
Wend
End With
Next
End With
End Sub

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
Hi
I was wondering if the macros can do this. I have code for find and replace.
The code works perfectly fine. But I want the way the output to be displayed
differently.

I want a dialog box it shd be divided into two parts. The top part of the
box should contain the sentence which has the mistaken[FIND WORD] word. The
mistaken word should displayed in green. The bottom part should have
suggestion words [REPLACE WORD].

Further the dialog box must YES , NO, AND IGNORE buttons. On clicking:
Yes- the word must be replaced
No- skip and go to next word
IGNORE- the checking shd get over.

ALL THIS SHD HAPPEN SEQUENTIALLY. If the are 2 different words eg, hi and
hello. When the macros encouter hi, change must occur.When the macros
encouter hello,change must occur. If the document has 10 hi's and 5 hello's.
Changes must occur as and when HI and HELLO occur. NOT change all 10 HI's at
one shot and then change all 5 HELLOS at one shot.
For example,

I have a pen. The pen is great. This pen is lovely. I like lovely things.

The code I got I have is
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "pen" 'the word to find
sRepText = "pencils" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "lovely" 'the word to find
sRepText = "bad" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend

It will be great if someone comes up with a solution.
Thanks for helping a novice.

Sally
 
D

Designingsally

Hi Pesach
Thanks. It helped me and suited my needs.

I want to know something.

Is it possible to code and do this find and replace like spell checker. Have
u observed the dialog box of the spell checker. Can this be coded on those
lines so as to get that output??
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

The following macro can do everything that you requested except color the
words. It is based on your code, but I introduced an array so that it
wouldn't be necessary to repeat the code for each FIND WORD/REPLACE WORD
pair. You can also easily add more pairs to the macro simply by adding them
to the array.

Sub PromptToReplace()

Dim orng As Range
Dim sRep As VbMsgBoxResult
Dim textArray As Variant
Dim i As Long

ReDim textArray(1 To 2, 1 To 2) As String
textArray(1, 1) = "pen"
textArray(1, 2) = "pencils"
textArray(2, 1) = "lovely"
textArray(2, 2) = "bad"
With Selection
For i = 1 To UBound(textArray, 1)
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=textArray(i, 1))
Set orng = Selection.Range
sRep = MsgBox("The incorrect word '" & _
textArray(i, 1) & _
"' was found in the following sentence:" _
& vbCrLf & orng.Sentences(1) & vbCrLf _
& vbCrLf & "Replace this word with '" & _
textArray(i, 2) & "'?", vbYesNoCancel)
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveStart Unit:=wdCharacter, Count:=1
If sRep = vbCancel Then
Exit Sub
ElseIf sRep = vbYes Then
orng.Text = textArray(i, 2)
End If
Wend
End With
Next
End With
End Sub

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
Hi
I was wondering if the macros can do this. I have code for find and replace.
The code works perfectly fine. But I want the way the output to be displayed
differently.

I want a dialog box it shd be divided into two parts. The top part of the
box should contain the sentence which has the mistaken[FIND WORD] word. The
mistaken word should displayed in green. The bottom part should have
suggestion words [REPLACE WORD].

Further the dialog box must YES , NO, AND IGNORE buttons. On clicking:
Yes- the word must be replaced
No- skip and go to next word
IGNORE- the checking shd get over.

ALL THIS SHD HAPPEN SEQUENTIALLY. If the are 2 different words eg, hi and
hello. When the macros encouter hi, change must occur.When the macros
encouter hello,change must occur. If the document has 10 hi's and 5 hello's.
Changes must occur as and when HI and HELLO occur. NOT change all 10 HI's at
one shot and then change all 5 HELLOS at one shot.
For example,

I have a pen. The pen is great. This pen is lovely. I like lovely things.

The code I got I have is
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "pen" 'the word to find
sRepText = "pencils" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "lovely" 'the word to find
sRepText = "bad" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend

It will be great if someone comes up with a solution.
Thanks for helping a novice.

Sally
 
P

Pesach Shelnitz

Hi Sally,

You can open many of the Word dialog boxes through the Application.Dialogs
property. See the WdWordDialog enumeration
(http://msdn.microsoft.com/en-us/library/bb214033.aspx ) for the specific
dialog boxes that can be opened this way, and, yes, the spell checker dialog
box is listed among them. For more information that will help get you started
with this, see Displaying Built-in Word Dialog Boxes
(http://msdn.microsoft.com/en-us/library/bb208857.aspx). For information
about the things that you can manipulate in specific dialog boxes, see
Built-in Dialog Box Argument Lists
(http://msdn.microsoft.com/en-us/library/aa211930.aspx ). Here is where you
will probably be disappointed in the case of the spell check dialog box.

In addition, the folder Browse, File Open, and File Save As dialog boxes can
be opened through the Application.FileDialog property.

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
Hi Pesach
Thanks. It helped me and suited my needs.

I want to know something.

Is it possible to code and do this find and replace like spell checker. Have
u observed the dialog box of the spell checker. Can this be coded on those
lines so as to get that output??
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

The following macro can do everything that you requested except color the
words. It is based on your code, but I introduced an array so that it
wouldn't be necessary to repeat the code for each FIND WORD/REPLACE WORD
pair. You can also easily add more pairs to the macro simply by adding them
to the array.

Sub PromptToReplace()

Dim orng As Range
Dim sRep As VbMsgBoxResult
Dim textArray As Variant
Dim i As Long

ReDim textArray(1 To 2, 1 To 2) As String
textArray(1, 1) = "pen"
textArray(1, 2) = "pencils"
textArray(2, 1) = "lovely"
textArray(2, 2) = "bad"
With Selection
For i = 1 To UBound(textArray, 1)
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=textArray(i, 1))
Set orng = Selection.Range
sRep = MsgBox("The incorrect word '" & _
textArray(i, 1) & _
"' was found in the following sentence:" _
& vbCrLf & orng.Sentences(1) & vbCrLf _
& vbCrLf & "Replace this word with '" & _
textArray(i, 2) & "'?", vbYesNoCancel)
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveStart Unit:=wdCharacter, Count:=1
If sRep = vbCancel Then
Exit Sub
ElseIf sRep = vbYes Then
orng.Text = textArray(i, 2)
End If
Wend
End With
Next
End With
End Sub

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
Hi
I was wondering if the macros can do this. I have code for find and replace.
The code works perfectly fine. But I want the way the output to be displayed
differently.

I want a dialog box it shd be divided into two parts. The top part of the
box should contain the sentence which has the mistaken[FIND WORD] word. The
mistaken word should displayed in green. The bottom part should have
suggestion words [REPLACE WORD].

Further the dialog box must YES , NO, AND IGNORE buttons. On clicking:
Yes- the word must be replaced
No- skip and go to next word
IGNORE- the checking shd get over.

ALL THIS SHD HAPPEN SEQUENTIALLY. If the are 2 different words eg, hi and
hello. When the macros encouter hi, change must occur.When the macros
encouter hello,change must occur. If the document has 10 hi's and 5 hello's.
Changes must occur as and when HI and HELLO occur. NOT change all 10 HI's at
one shot and then change all 5 HELLOS at one shot.
For example,

I have a pen. The pen is great. This pen is lovely. I like lovely things.

The code I got I have is
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "pen" 'the word to find
sRepText = "pencils" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "lovely" 'the word to find
sRepText = "bad" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend

It will be great if someone comes up with a solution.
Thanks for helping a novice.

Sally
 
D

Designingsally

Hi Pesach

Thanks for the reply.

Do you know how it can be implemented into this particular help.

Thanks for the help

Sally
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

You can open many of the Word dialog boxes through the Application.Dialogs
property. See the WdWordDialog enumeration
(http://msdn.microsoft.com/en-us/library/bb214033.aspx ) for the specific
dialog boxes that can be opened this way, and, yes, the spell checker dialog
box is listed among them. For more information that will help get you started
with this, see Displaying Built-in Word Dialog Boxes
(http://msdn.microsoft.com/en-us/library/bb208857.aspx). For information
about the things that you can manipulate in specific dialog boxes, see
Built-in Dialog Box Argument Lists
(http://msdn.microsoft.com/en-us/library/aa211930.aspx ). Here is where you
will probably be disappointed in the case of the spell check dialog box.

In addition, the folder Browse, File Open, and File Save As dialog boxes can
be opened through the Application.FileDialog property.

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
Hi Pesach
Thanks. It helped me and suited my needs.

I want to know something.

Is it possible to code and do this find and replace like spell checker. Have
u observed the dialog box of the spell checker. Can this be coded on those
lines so as to get that output??
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

The following macro can do everything that you requested except color the
words. It is based on your code, but I introduced an array so that it
wouldn't be necessary to repeat the code for each FIND WORD/REPLACE WORD
pair. You can also easily add more pairs to the macro simply by adding them
to the array.

Sub PromptToReplace()

Dim orng As Range
Dim sRep As VbMsgBoxResult
Dim textArray As Variant
Dim i As Long

ReDim textArray(1 To 2, 1 To 2) As String
textArray(1, 1) = "pen"
textArray(1, 2) = "pencils"
textArray(2, 1) = "lovely"
textArray(2, 2) = "bad"
With Selection
For i = 1 To UBound(textArray, 1)
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=textArray(i, 1))
Set orng = Selection.Range
sRep = MsgBox("The incorrect word '" & _
textArray(i, 1) & _
"' was found in the following sentence:" _
& vbCrLf & orng.Sentences(1) & vbCrLf _
& vbCrLf & "Replace this word with '" & _
textArray(i, 2) & "'?", vbYesNoCancel)
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveStart Unit:=wdCharacter, Count:=1
If sRep = vbCancel Then
Exit Sub
ElseIf sRep = vbYes Then
orng.Text = textArray(i, 2)
End If
Wend
End With
Next
End With
End Sub

--
Hope this helps,
Pesach Shelnitz


:

Hi
I was wondering if the macros can do this. I have code for find and replace.
The code works perfectly fine. But I want the way the output to be displayed
differently.

I want a dialog box it shd be divided into two parts. The top part of the
box should contain the sentence which has the mistaken[FIND WORD] word. The
mistaken word should displayed in green. The bottom part should have
suggestion words [REPLACE WORD].

Further the dialog box must YES , NO, AND IGNORE buttons. On clicking:
Yes- the word must be replaced
No- skip and go to next word
IGNORE- the checking shd get over.

ALL THIS SHD HAPPEN SEQUENTIALLY. If the are 2 different words eg, hi and
hello. When the macros encouter hi, change must occur.When the macros
encouter hello,change must occur. If the document has 10 hi's and 5 hello's.
Changes must occur as and when HI and HELLO occur. NOT change all 10 HI's at
one shot and then change all 5 HELLOS at one shot.
For example,

I have a pen. The pen is great. This pen is lovely. I like lovely things.

The code I got I have is
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "pen" 'the word to find
sRepText = "pencils" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "lovely" 'the word to find
sRepText = "bad" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend

It will be great if someone comes up with a solution.
Thanks for helping a novice.

Sally
 
D

Designingsally

Hi

I wanted to add this. I want the entire, find and replace macro appear like
the spell checker. You have seen how the spell checker in MS WORD. I want
this APPPEAR like that. SO that it can be more user friendly.

Pls convey ur thoughts

Thanks for the help in advance.


Sally
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

You can open many of the Word dialog boxes through the Application.Dialogs
property. See the WdWordDialog enumeration
(http://msdn.microsoft.com/en-us/library/bb214033.aspx ) for the specific
dialog boxes that can be opened this way, and, yes, the spell checker dialog
box is listed among them. For more information that will help get you started
with this, see Displaying Built-in Word Dialog Boxes
(http://msdn.microsoft.com/en-us/library/bb208857.aspx). For information
about the things that you can manipulate in specific dialog boxes, see
Built-in Dialog Box Argument Lists
(http://msdn.microsoft.com/en-us/library/aa211930.aspx ). Here is where you
will probably be disappointed in the case of the spell check dialog box.

In addition, the folder Browse, File Open, and File Save As dialog boxes can
be opened through the Application.FileDialog property.

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
Hi Pesach
Thanks. It helped me and suited my needs.

I want to know something.

Is it possible to code and do this find and replace like spell checker. Have
u observed the dialog box of the spell checker. Can this be coded on those
lines so as to get that output??
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

The following macro can do everything that you requested except color the
words. It is based on your code, but I introduced an array so that it
wouldn't be necessary to repeat the code for each FIND WORD/REPLACE WORD
pair. You can also easily add more pairs to the macro simply by adding them
to the array.

Sub PromptToReplace()

Dim orng As Range
Dim sRep As VbMsgBoxResult
Dim textArray As Variant
Dim i As Long

ReDim textArray(1 To 2, 1 To 2) As String
textArray(1, 1) = "pen"
textArray(1, 2) = "pencils"
textArray(2, 1) = "lovely"
textArray(2, 2) = "bad"
With Selection
For i = 1 To UBound(textArray, 1)
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=textArray(i, 1))
Set orng = Selection.Range
sRep = MsgBox("The incorrect word '" & _
textArray(i, 1) & _
"' was found in the following sentence:" _
& vbCrLf & orng.Sentences(1) & vbCrLf _
& vbCrLf & "Replace this word with '" & _
textArray(i, 2) & "'?", vbYesNoCancel)
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveStart Unit:=wdCharacter, Count:=1
If sRep = vbCancel Then
Exit Sub
ElseIf sRep = vbYes Then
orng.Text = textArray(i, 2)
End If
Wend
End With
Next
End With
End Sub

--
Hope this helps,
Pesach Shelnitz


:

Hi
I was wondering if the macros can do this. I have code for find and replace.
The code works perfectly fine. But I want the way the output to be displayed
differently.

I want a dialog box it shd be divided into two parts. The top part of the
box should contain the sentence which has the mistaken[FIND WORD] word. The
mistaken word should displayed in green. The bottom part should have
suggestion words [REPLACE WORD].

Further the dialog box must YES , NO, AND IGNORE buttons. On clicking:
Yes- the word must be replaced
No- skip and go to next word
IGNORE- the checking shd get over.

ALL THIS SHD HAPPEN SEQUENTIALLY. If the are 2 different words eg, hi and
hello. When the macros encouter hi, change must occur.When the macros
encouter hello,change must occur. If the document has 10 hi's and 5 hello's.
Changes must occur as and when HI and HELLO occur. NOT change all 10 HI's at
one shot and then change all 5 HELLOS at one shot.
For example,

I have a pen. The pen is great. This pen is lovely. I like lovely things.

The code I got I have is
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "pen" 'the word to find
sRepText = "pencils" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "lovely" 'the word to find
sRepText = "bad" 'the word to replace
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend

It will be great if someone comes up with a solution.
Thanks for helping a novice.

Sally
 

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