Finding Multiple instances of a style and offering change of style

J

JB

Hi Folks,
I'm trying to get a code sample working which finds a particular style (HRef
of which there may be many on the same document) and give the user a choice
of keeping the style of replacing the style with Normal.

Below is what I have so far, problem is I only want it to do this once per
style found and not loop round the document 50 times.

Tips Appreciated

J

Public Sub HRef()

Selection.WholeStory
Selection.MoveLeft wdCharacter, 1
iCount = 0
ActiveDocument.ActiveWindow.View.ShowHiddenText = True

Do Until iCount > 50
If iCount = 0 Then
Selection.HomeKey
End If

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("HRef")

With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With

Selection.Find.Execute

x = Selection.Characters.count
Selection.MoveRight wdCharacter, 1
Selection.MoveRight wdCharacter, 2, wdExtend

If Selection.Style <> "Anchor" Then

Selection.MoveLeft wdCharacter, 1
Selection.MoveLeft wdCharacter, x, wdExtend
Reply = (MsgBox(strMessage, vbYesNo, strTitle))

If Reply = vbYes Then
Selection.Style = "Default Paragraph Font"
End If
Else
bGood = True
End If
iCount = iCount + 1
Loop

End Sub
 
S

Steve Lang

HI JB,

Move your loop:

'identify your find criteria

'execute the find
Selection.Find.Execute
Do While Selection.Find.found
'do stuff to what was found
'blah blah blah

'execute the find again to continue the process
Selection.Find.Execute
Loop


HTH and have a great day!

Steve
 
J

JB

Steve said:
HI JB,

Move your loop:

'identify your find criteria

'execute the find
Selection.Find.Execute
Do While Selection.Find.found
'do stuff to what was found
'blah blah blah

'execute the find again to continue the process
Selection.Find.Execute
Loop


HTH and have a great day!

Steve
Good Man Steve! Worked a treat
 

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

Similar Threads


Top