![]() |
|
#1
|
|||
|
|||
|
I have some code that finds text before the first colon or tab at the beginning of paragraphs and formats bold for definitions. I've found an issue in that if there is an opening square bracket at the beginning of the paragraph, the text remains plain after the code has run. I've tried adding ([\[]) before ([a-zA-Z0-9] but that only converted the text with the square bracket bold and left everything else. How can I get the code to include the square bracket when running the code?
Before code has run Before Image.JPG After code has run After image.JPG Test doc Test Doc - Bold text before colon or tab.docx Code:
Sub Test_BoldText()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
.Replacement.ClearFormatting
'Find text before first tab or colon and format bold
.text = "([a-zA-Z0-9][!^13]@)([^t:])"
While .Execute
If oRng.Characters(1).Start = oRng.Paragraphs(1).Range.Characters(1).Start Then
oRng.Select
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
End Sub
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Automatically put a text string at the beginning of a paragraph | jthomas666 | Word | 2 | 08-22-2019 12:27 PM |
Word macro to insert text at the beginning of paragraph but skip tables
|
ashalles135 | Word VBA | 5 | 09-26-2018 09:49 AM |
word macro To insert text at the beginning and at end of paragraph
|
ArieH | Word VBA | 20 | 09-10-2017 04:23 PM |
Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank
|
caboy | Word VBA | 2 | 04-01-2015 07:00 AM |
| Looping macros to add text to beginning and end of a paragraph | pachmarhi | Word VBA | 0 | 02-16-2009 06:57 AM |