#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Hi, RobiNew! I didn't try it, but this may work:
Code:
'If oRng.Find.Found And oRng.Characters.First.Previous Like "[!.?-–»]" Then |
#3
|
|||
|
|||
Hi, Vivka! It works OK with '.Last.Previous' and 'Like'.Thanks a lot!
|
#4
|
|||
|
|||
Good! You are welcome!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Add contents of specific cell into next column in range with specific string of characters | silverman166 | Excel | 5 | 02-08-2024 07:58 AM |
Select a specific number of characters in word using VBA | mrwoggie | Word VBA | 1 | 01-18-2022 03:08 PM |
A Macro to break lines automatically after specific number of characters | Annie Wordy | Word VBA | 1 | 11-03-2017 08:36 PM |
My style keeps changing, can't get saved style to apply | Meenie50 | Word | 7 | 07-20-2017 03:47 PM |
How can I easily preceded the title of a saved Outlook Message with the date and number | Chris Waller | Outlook | 0 | 09-01-2016 12:45 PM |