Link to home
Start Free TrialLog in
Avatar of Member_2_8045560
Member_2_8045560

asked on

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.
Avatar of abbas abdulla
abbas abdulla
Flag of Bahrain image

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
Avatar of Member_2_8045560
Member_2_8045560

ASKER

Thank you for your effort, but I don't want to replace the style instead I want to replace text
Hi,
Share sample of the word file and let me know what do you need to replace with what?
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
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
Tried but loops continuously
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow thanks, it does the trick.
Solution according to author's comment