View Single Post
 
Old 01-27-2025, 07:02 AM
gmaxey gmaxey is offline Windows 10 Office 2019
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

Paul is undisputed absolute master of using and keeping track of complex split or replace strings and yes they work very well!


The following is by no means superior, but you might find it easier to understand:

Code:
Sub Modified_MacroPod_Demo()
'A few more variables
Dim varParts
Dim varMonths
Dim LS As String
Dim lngMonthIndex As Long
Dim oRng As Range, oRngCheck As Range
  Application.ScreenUpdating = False
  Application.CheckLanguage = True
  'Get the regional list separator for use in the find string.
  LS = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Control Panel\International\sList")
  'Define the various month replacments in a string, then convert to an array.
  varMonths = Split("janv.|févr.|mars|avr.|mai|juin|juill.|août|sept.|oct.|nov.|déc.", "|")
  Set oRng = Selection.Range
  
  With oRng
    Set oRngCheck = .Duplicate
    .LanguageID = wdFrenchCanadian
    .NoProofing = False
  End With
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    'Modified using the regional list separator character.
    .Text = "<[JFMASOND][a-z.]{2" & LS & "9} [0-9]{1" & LS & "2}, [0-9]{2" & LS & "4}>"
    .Replacement.Text = ""
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Forward = True
    .Format = False
    Do While .Execute
      With oRng
        If .InRange(oRngCheck) Then
          'Create an array of the date parts i.e., day, month, year.
          varParts = Split(oRng.Text, " ")
          'Find the index of the month part.
          lngMonthIndex = Month("1 " & (Left(varParts(0), 3)) & " 2025")
          'If the year part is only 2 digits, prefix with "20"
          If Len(varParts(2)) = 2 Then varParts(2) = "20" & varParts(2)
          'Build the replacement string.
          'a) The "day" part will include the comma.  Strip it out: Replace(varParts(1), ",", "")
          'b) The "month" part will be pulled from varMonths defined above: varMonths(lngMonthIndex - 1)
          .Text = Replace(varParts(1), ",", "") & " " & varMonths(lngMonthIndex - 1) & " " & varParts(2)
          .Font.Color = 16711937
          .Collapse wdCollapseEnd
        Else
          Exit Do
        End If
      End With
    Loop
  End With
  Application.ScreenUpdating = True
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 01-27-2025 at 12:38 PM.
Reply With Quote