Find and replace other than given style

Dear All,
This is Iliyas, I have this query, i.e., in word document I have style named 'F-Caption' and other styles. I need to find and replace other than the style 'F-Caption' (should not find in the text with style 'F-Caption'). I'm looking for your quick reply. Thanks in advance.
Mohamed iliyasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abbas abdullaCommented:
Hi,

Check this code
Sub FindAndChangeStyle()
Dim i As Paragraph
'Find Normal style and format it to be Heading 1 style
  For Each i In ActiveDocument.Paragraphs
        If i.Style.NameLocal = "Normal" And Len(i.Range.Text) > 1 Then
            i.Range.Style = ActiveDocument.Styles("Heading 1")

        End If
    Next
   
End Sub
0
Mohamed iliyasAuthor Commented:
Thank you for your effort, but I don't want to replace the style instead I want to replace text
0
abbas abdullaCommented:
Hi,
Share sample of the word file and let me know what do you need to replace with what?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Mohamed iliyasAuthor Commented:
Hi
In the attached document, should replace "p." into "S." except the text with style "Float-Caption".
Thanks in advance.
329063_0_En_31-1_Chapter.DOCX
0
Rgonzo1971Commented:
Hi,

pls try
Sub Macro()
    Dim r As Range
    Set r = ActiveDocument.Range
    With r.Find
        Do While .Execute(Findtext:="p.", Forward:=True) = True
            If r.Style.NameLocal <> "Float-Caption" Then
                r.Text = "S."
                r.Collapse 0
            End If
        Loop
    End With

End Sub

Open in new window

Regards
0
Mohamed iliyasAuthor Commented:
Tried but loops continuously
0
Rgonzo1971Commented:
then try
Sub Macro()
    Dim r As Range
    
    Set r = ActiveDocument.Range
    Selection.EndKey Unit:=wdStory, Extend:=wdMove
    With r.Find
        Do While .Execute(Findtext:="p.", Forward:=False) = True
            If r.Style.NameLocal <> "Float-Caption" Then
                r.Text = "S."
                r.Collapse 0
            End If
        Loop
    End With

End Sub

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohamed iliyasAuthor Commented:
Wow thanks, it does the trick.
0
Rgonzo1971Commented:
Solution according to author's comment
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.