![]() |
|
#5
|
|||
|
|||
|
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. |
| Tags |
| regex, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Regular expression confusion!
|
VBAFiddler | Word VBA | 11 | 02-13-2021 01:16 AM |
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 |
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 |