View Single Post
 
Old 03-20-2024, 10:30 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default Apply style if fnt ref number preceded by specific characters

I'm trying to devise a code to apply a specific style if the fnt ref number followed by a return is preceded by specific characters. I need help with the if-condition. Thanks!
Code:
Sub FormatThese()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
Do
With oRng.Find
.MatchWildcards = False
.Text = "^f^p" 'find this sequence
.Replacement.Text = ""
.Wrap = wdFindStop
.Execute
End With
'oRng.Select
'If found and sequence preceded by one of these characters: "!.?-–»" Then
'If oRng.Find.Found And oRng.Characters.Last.Previous = "[!.?-–»]" Then
If oRng.Find.Found Then
oRng.Style = "myStyle"
Else: Exit Do
End If
oRng.Collapse 0
Loop
Set oRng = Nothing
End Sub
Reply With Quote