Looking for a better way
- From: "Greg" <gmaxey@xxxxxxxx>
- Date: 2 Dec 2005 05:13:35 -0800
Earlier I was helping a user that wanted a VBA find routine that would
start at the IP and go to the end of the document. On reaching the
end, the user wanted a pop-up to querry if the routine should loop to
the begining of the document. I got that far without any trouble.
However, I got tripped up trying to stop the routine at the IP after it
began searching from the document start. I scrapped together something
that appears workable, but it seems I am missing something simple.
Review and comments welcomed.
Sub ScratchMacro()
Dim oRng As Range
Dim oRng1 As Range
Dim oRng2 As Range
Dim i As Long
Dim bLooped As Boolean
Set oRng1 = ActiveDocument.Content
Set oRng2 = ActiveDocument.Content
i = Selection.Start
oRng1.Start = i
oRng2.End = i
Set oRng = oRng1
bLooped = False
LoopTwo:
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Font.Italic = True
.Wrap = wdFindStop
Do While .Execute
If bLooped = True And oRng.Start > i Then
MsgBox "Finished."
Exit Sub
End If
oRng.HighlightColorIndex = wdYellow
Select Case MsgBox("Do you want to remove italics from: " _
& oRng.Text, vbYesNoCancel, "Action")
Case Is = vbYes
oRng.Font.Italic = False
oRng.HighlightColorIndex = wdNoHighlight
oRng.Collapse wdCollapseEnd
Case Is = vbNo
oRng.HighlightColorIndex = wdNoHighlight
oRng.Collapse wdCollapseEnd
Case Is = vbCancel
oRng.HighlightColorIndex = wdNoHighlight
Exit Do
End Select
Loop
End With
If bLooped = False Then
If MsgBox("Do you want to loop to start?", _
vbYesNo, "Loop to Start") = vbYes Then
bLooped = True
Set oRng = oRng2
GoTo LoopTwo
End If
End If
End Sub
.
- Follow-Ups:
- Re: Looking for a better way
- From: Tony Jollans
- Re: Looking for a better way
- Prev by Date: Re: Look for italicized word,msgbox asks to remove,finds next ital
- Next by Date: Display of folder on FTP site
- Previous by thread: Re: Change Page Section Type
- Next by thread: Re: Looking for a better way
- Index(es):
Relevant Pages
|