Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 07-30-2025, 10:37 PM
vivka vivka is offline Using Regular Expression in Find Windows 7 64bit Using Regular Expression in Find Office 2016
Expert
 
Join Date: Jul 2023
Posts: 305
vivka is on a distinguished road
Default

Thank you, Greg, for your remarks! I fully accept them. My final code taking advantage of your suggestions (If conditions can be replaced wih Case conditions):
Code:
Sub Find_N_Embolden()
'In selection, embolden all '@AnyNumberOfCapitals' or
''@AnyNumberOfCapitals_DigitDigitNotFollowedByDigitOrLetter'.

Dim oRng As range
Dim FindTxt As String
 
    Application.ScreenUpdating = False
    Set oRng = Selection.range
    
    FindTxt = "\@[A-Z]{1,}"
    Do
        With oRng.Find
            .text = FindTxt
            .MatchWildcards = True
            .Forward = True
            .Wrap = wdFindStop
            If .Execute And oRng.InRange(Selection.range) Then
                If oRng.End >= ActiveDocument.range.End - 4 Then
                    oRng.Font.Bold = True: GoTo lbl_Next
                ElseIf oRng.Characters.Last.Next <> "_" Then
                    oRng.Font.Bold = True: GoTo lbl_Next
                ElseIf Right(ActiveDocument.range(oRng.start, oRng.End + 4), 4) Like "_[0-9][0-9][!A-Za-z0-9]" Then
                    oRng.MoveEnd unit:=wdCharacter, count:=3
                    oRng.Font.Bold = True: GoTo lbl_Next
                Else: GoTo lbl_Next
                End If
            Else
                Exit Do
            End If
        End With
lbl_Next:
        oRng.Collapse wdCollapseEnd
     Loop
Application.ScreenUpdating = True
Set oRng = Nothing
End Sub

Last edited by vivka; 07-31-2025 at 06:59 AM.
Reply With Quote
 

Tags
regex, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Regular Expression in Find Regular expression confusion! VBAFiddler Word VBA 11 02-13-2021 01:16 AM
Using Regular Expression in Find find/replace wildcard expression help LQuinn Word VBA 2 01-28-2021 11:57 PM
Is it possible to use wild cards or regular expression in autocorrect kcvinu Word 2 12-14-2018 02:06 PM
Using Regular Expression in Find Regular Expression Syntax to Search for Alternative Words qubie Word 2 11-29-2017 05:48 AM
VBA code to enable Regular Expression ronmayerle Word VBA 2 11-20-2014 01:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:50 AM.


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