View Single Post
 
Old 05-14-2025, 05:54 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Expert
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA format text before colon issue with square bracket

Hi, I've been working with the below code which G Maxy helped me with some time ago. The code works well except if there is an opening square bracket at the beginning of the text when the code is looking for a tab or a colon. I've tried adding ([\[] at the beginning but nothing seems to be working. Can anyone advise where I'm going wrong. Thanks

Before code has run
Before Image.JPG

After code has run
After Image.JPG

Code:
With oRng.Find
    .ClearFormatting
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchWildcards = True
    .Replacement.ClearFormatting
    .text = "([a-zA-Z0-9][!^13]@)([^t:])"
    'Find text before first tab or colon and format bold and remove colon
    While .Execute
       If oRng.Characters(1).Start = oRng.Paragraphs(1).Range.Characters(1).Start Then
         oRng.Font.Bold = True
         If Not oRng.Characters.Last.Next = vbTab Then
           oRng.text = Replace(oRng.text, ":", vbTab)
         Else
           oRng.Characters.Last.Delete
         End If
       End If
    Wend
  End With
Reply With Quote