Zoomie
02-12-2022, 06:42 PM
As indicated in my reply to your cross-post (q.v.), if there isn't any content that might be affected outside tables, you could simply use:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Replacement.Text = "^&"
.Text = "\[[0-9.]{1,}\]"
.Replacement.Font.ColorIndex = wdBlue
.Execute Replace:=wdReplaceAll
.Text = "[\[\]]"
.Replacement.Font.ColorIndex = wdAuto
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub
Hi! I'm bringing this thread up because I found it when I was looking for a way to apply a font color to numbers inside brackets in my 400 page word document. The only difference is that I'm looking to apply the font color ONLY to numbers between [] brackets. Occasionally, I have something like this: [124; 125; 3456] and in that case, the font color should only be applied to the numbers, not the semicolons.
Is there a way to modify the above code to accommodate this exception? Also, can I use RGB or HEX color codes? I'm not sure I understand the VB commands properly.
Thank you for anyone who can help!
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Replacement.Text = "^&"
.Text = "\[[0-9.]{1,}\]"
.Replacement.Font.ColorIndex = wdBlue
.Execute Replace:=wdReplaceAll
.Text = "[\[\]]"
.Replacement.Font.ColorIndex = wdAuto
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub
Hi! I'm bringing this thread up because I found it when I was looking for a way to apply a font color to numbers inside brackets in my 400 page word document. The only difference is that I'm looking to apply the font color ONLY to numbers between [] brackets. Occasionally, I have something like this: [124; 125; 3456] and in that case, the font color should only be applied to the numbers, not the semicolons.
Is there a way to modify the above code to accommodate this exception? Also, can I use RGB or HEX color codes? I'm not sure I understand the VB commands properly.
Thank you for anyone who can help!