Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2024, 10:30 AM
RobiNew RobiNew is offline Apply style if fnt ref number preceded by specific characters Windows 10 Apply style if fnt ref number preceded by specific characters Office 2016
Competent Performer
Apply style if fnt ref number preceded by specific characters
 
Join Date: Sep 2023
Posts: 183
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
  #2  
Old 03-20-2024, 01:17 PM
vivka vivka is offline Apply style if fnt ref number preceded by specific characters Windows 7 64bit Apply style if fnt ref number preceded by specific characters Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew! I didn't try it, but this may work:
Code:
'If oRng.Find.Found And oRng.Characters.First.Previous Like "[!.?-–»]" Then
Reply With Quote
  #3  
Old 03-20-2024, 03:28 PM
RobiNew RobiNew is offline Apply style if fnt ref number preceded by specific characters Windows 10 Apply style if fnt ref number preceded by specific characters Office 2016
Competent Performer
Apply style if fnt ref number preceded by specific characters
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi, Vivka! It works OK with '.Last.Previous' and 'Like'.Thanks a lot!
Reply With Quote
  #4  
Old 03-20-2024, 10:55 PM
vivka vivka is offline Apply style if fnt ref number preceded by specific characters Windows 7 64bit Apply style if fnt ref number preceded by specific characters Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Good! You are welcome!
Reply With Quote
Reply



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
Apply style if fnt ref number preceded by specific characters Select a specific number of characters in word using VBA mrwoggie Word VBA 1 01-18-2022 03:08 PM
Apply style if fnt ref number preceded by specific characters 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft