See the article "Clear settings from Find and Replace dialog to prevent
unexpected results from future Find or Replace operations†at:
http://www.word.mvps.org/FAQs/MacrosVBA/ClearFind.htm
--
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
Hi Doug,
When running your code, I get the following:
"Microsoft Visual Basic
Run-time error 5623 The Replace With text contains a group number which
is
out of range. [Continue] [End] [Debug] [Help]"
Pushing the [Debug] key highlights the following text:
"If Selection.Find.Execute(FindText:=monthArray(i - 1), _
Wrap:=wdFindStop, Forward:=True) = True Then"
I copied your code exactly.
:
To do that, use:
Sub FindaMonth()
Dim monthArray As Variant
Dim i As Long
monthArray = Split("January,February,March,April,May," & _
"June,July,August,September,October,November,December", ",")
For i = 1 To 12
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
If Selection.Find.Execute(FindText:=monthArray(i - 1), _
Wrap:=wdFindStop, Forward:=True) = True Then
Exit Sub
End If
Next
MsgBox "There are no months in the document." 'Just in case there
are
no months and you thought that nothing was happening.
End Sub
--
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
message
Toda Pesach
One question though: What is the significance of the report e.g.
"July
found
at 19598"? Is there perhaps some way it can take me to that
incidence?
Shalom
:
Hi Johann,
I was tempted to tell you that this could be done using a wildcard
search,
but since the names of the months have different lengths and May
consists
of
only three letters, siuch a search would find many other words
besides
the
names of the months. I therefore wrote the following macro which
searches
through the doc 12 times, but since it performs the searches on a
Range
object rather than the Selection object, it can do the work quickly
even
in a
large doc.
Sub FindMonths()
Dim monthArray As Variant
Dim myRange As Range
Dim i As Long
monthArray = Split("January,February,March,April,May," & _
"June,July,August,September,October,November,December",
",")
Set myRange = ActiveDocument.Range
With myRange
For i = 1 To 12
.Start = 0
Do While .Find.Execute(FindText:=monthArray(i - 1), _
Wrap:=wdFindStop, Forward:=True) = True
Select Case i
Case 1
' Replace the following line by the actions
' to be performed when January is found.
MsgBox "January found at " & .Start
Case 2
' Replace the following line by the actions
' to be performed when February is found.
MsgBox "February found at " & .Start
Case 3
' Replace the following line by the actions
' to be performed when March is found.
MsgBox "March found at " & .Start
Case 4
' Replace the following line by the actions
' to be performed when April is found.
MsgBox "April found at " & .Start
Case 5
' Replace the following line by the actions
' to be performed when May is found.
MsgBox "May found at " & .Start
Case 6
' Replace the following line by the actions
' to be performed when June is found.
MsgBox "June found at " & .Start
Case 7
' Replace the following line by the actions
' to be performed when July is found.
MsgBox "July found at " & .Start
Case 8
' Replace the following line by the actions
' to be performed when August is found.
MsgBox "August found at " & .Start
Case 9
' Replace the following line by the actions
' to be performed when September is found.
MsgBox "September found at " & .Start
Case 10
' Replace the following line by the actions
' to be performed when October is found.
MsgBox "October found at " & .Start
Case 11
' Replace the following line by the actions
' to be performed when November is found.
MsgBox "November found at " & .Start
Case 12
' Replace the following line by the actions
' to be performed when December is found.
MsgBox "December found at " & .Start
End Select
.MoveStart 1
.End = ActiveDocument.Range.End
Loop
Next
End With
Set myRange = Nothing
End Sub
--
Hope this helps,
Pesach Shelnitz
:
Is it possible to use the Find (Search) function to find either
January
or
February or March, etc, perhaps by using a macro? I would like
not
to
have to
use 12 different searches to search for the 12 months.
The action after having found a particular month varies; I
manually
apply an
action and then resume the search to the next incidence.