L
LiCal
I need help in nesting a Find and Replace Macro into another one.
1. In the word document, the main macro is to find the string "Fri -
Sun" individually; then extend the selection to end of line.
2. the nested marco is then used to replace spaces within the line
selection with tabs.
The below nested Macro will run, but needs Ctrl-Break to stop it; I
appreciate some help in clarifying the usage of the below paramaters
for both Main/sub marcos.
---------------------------------------------
.Forward = (? true ; False)
.Wrap (?wdFindAsk ; wdFindContinue ; wdFindStop)
---------------------------------------------
is it possible to/ how to code NO for the answer to the
wdFindask (Ctrl-H) Dialog Box?
(The msg : Word has finished searching the selection. x replacements
were made. Do you wan to search the remainder of the document? Yes /
No)
=======================================
'+++++++++++++++++++++++++++
Sub MainFindReplace()
'+++++++++++++++++++++++++++
Set rDcm = ActiveDocument.Range
rDcm.Find.ClearFormatting
With Selection.Find
Ia = 0
'.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Do While .Execute(FindText:="Fri - Sun") = True
Ia = Ia + 1 ' Counter
' extend the selection to the end of line
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
' Nested Macro to find/replace spaces in the selection to Tabs.
SubFindReplace
Loop
End With
MsgBox "IA= " & Ia
End Sub
'++++++++++++++++++++++++++++
Sub SubFindReplace()
'++++++++++++++++++++++++++++
' Macro24 Macro
' Macro recorded 2/9/2009 by OEM
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = "^t"
.Forward = False
.Wrap = wdFindStop 'wdFindAsk ;
wdFindContinue ; wdFindStop
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'SendKeys "N"
'Resetting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
End Sub
--
1. In the word document, the main macro is to find the string "Fri -
Sun" individually; then extend the selection to end of line.
2. the nested marco is then used to replace spaces within the line
selection with tabs.
The below nested Macro will run, but needs Ctrl-Break to stop it; I
appreciate some help in clarifying the usage of the below paramaters
for both Main/sub marcos.
---------------------------------------------
.Forward = (? true ; False)
.Wrap (?wdFindAsk ; wdFindContinue ; wdFindStop)
---------------------------------------------
is it possible to/ how to code NO for the answer to the
wdFindask (Ctrl-H) Dialog Box?
(The msg : Word has finished searching the selection. x replacements
were made. Do you wan to search the remainder of the document? Yes /
No)
=======================================
'+++++++++++++++++++++++++++
Sub MainFindReplace()
'+++++++++++++++++++++++++++
Set rDcm = ActiveDocument.Range
rDcm.Find.ClearFormatting
With Selection.Find
Ia = 0
'.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Do While .Execute(FindText:="Fri - Sun") = True
Ia = Ia + 1 ' Counter
' extend the selection to the end of line
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
' Nested Macro to find/replace spaces in the selection to Tabs.
SubFindReplace
Loop
End With
MsgBox "IA= " & Ia
End Sub
'++++++++++++++++++++++++++++
Sub SubFindReplace()
'++++++++++++++++++++++++++++
' Macro24 Macro
' Macro recorded 2/9/2009 by OEM
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = "^t"
.Forward = False
.Wrap = wdFindStop 'wdFindAsk ;
wdFindContinue ; wdFindStop
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'SendKeys "N"
'Resetting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
End Sub
--