Thread: underline date
View Single Post
 
Old 07-07-2017, 06:12 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You make things harder than they have to be:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/7/2017
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"
    .Format = True
    .Forward = True
    .MatchWildcards = True
    While .Execute
      With oRng
        If IsDate(.Text) Then
          .Text = Format(oRng.Text, "dd.mm.yyyy")
          .Font.Underline = True
        End If
        .Collapse wdCollapseEnd
      End With
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote