Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 07-23-2025, 08:55 AM
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: 302
vivka is on a distinguished road
Default

Hi! Unfortunately, you can't use a one-line regex to do this. Try the following, which will work on the selecton, not on the entire doc (it's my personal preference):
Code:
Sub Find_N_Embolden()

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

Last edited by vivka; 07-23-2025 at 10:12 PM.
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 02:53 PM.


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