View Single Post
 
Old 01-26-2025, 11:03 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In which case you could use:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, StrYY As String, StrMM As String, StrDD As String
Application.CheckLanguage = True
With Selection
  Set Rng = .Range
  .LanguageID = wdFrenchCanadian
  .NoProofing = False
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "<[JFMASOND][a-z.]{2;9} [0-9]{1;2}, [0-9]{2;4}>"
      .Replacement.Text = ""
      .MatchWildcards = True
      .Wrap = wdFindStop
      .Forward = True
      .Format = False
    End With
    Do While .Find.Execute
      If .InRange(Rng) Then
        StrYY = Split(.Text, " ")(2): StrMM = Left(Split(.Text, " ")(0), 3): StrDD = Split(Split(.Text, " ")(1), ",")(0)
        If Len(StrYY) = 2 Then StrYY = "20" & StrYY
         Select Case StrMM
          Case "Jan": StrMM = " janv. "
          Case "Feb": StrMM = " févr. "
          Case "Mar": StrMM = " mars "
          Case "Apr": StrMM = " avr. "
          Case "May": StrMM = " mai "
          Case "Jun": StrMM = " juin "
          Case "Jul": StrMM = " juill. "
          Case "Aug": StrMM = " août "
          Case "Sep": StrMM = " sept. "
          Case "Oct": StrMM = " oct. "
          Case "Nov": StrMM = " nov. "
          Case "Dec": StrMM = " déc. "
        End Select
        .Text = StrDD & StrMM & StrYY
        .Font.Color = 16711937 'Blue HTML 1/1/255
      Else
        Exit Do
      End If
      .Collapse wdCollapseEnd
    Loop
  End With
End With
Application.ScreenUpdating = True
End Sub
With the Find expression:
• <[JFMASOND][a-z.]{2;9} looks for the month, with or without the abbreviation period and regardless of whether it's in a short date or long date format;
• [0-9]{1;2}, looks for the day; and
• [0-9]{2;4}> looks for the year in 2-digit to 4-digit format.
The Split function can be used to separate out different elements as a string. By splitting the string at each space, the various parts of the date can be differentiated as if they're a 0-based array. So, given the Find pattern:
• Split(.Text, " ")(0) gets the month;
• Split(.Text, " ")(1) gets the day. Nesting it, thus Split(Split(.Text, " ")(1), ",")(0), eliminates the comma, if present; and
• Split(.Text, " ")(2) gets the year
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote