View Single Post
 
Old 08-18-2022, 07:37 PM
Piet Bourke Piet Bourke is offline Windows 10 Office 2016
Novice
 
Join Date: Aug 2022
Posts: 2
Piet Bourke is on a distinguished road
Default

That code mostly works, except there's a bug that means it ruins all date pickers in the document.

I reordered it slightly:

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, j As String, Rng As Range
With ContentControl
  If .Type <> wdContentControlDate Then Exit Sub

  If .Title = "MyDate" Then
    .Type = wdContentControlRichText
  Set Rng = .Range
    For i = 0 To UBound(Split(.Range.Text, " "))
      j = Split(.Range.Text, " ")(i)
      If IsNumeric(j) Then
          With Rng
            .Start = .Start + InStr(ContentControl.Range.Text, j) + Len(j) - 1
            .End = .Start
            .InsertAfter Ordinal(Val(j))
            .Font.Superscript = True
          End With
          
        Exit For
      End If
    Next
    .Type = wdContentControlDate
  End If
End With
End Sub

Last edited by Piet Bourke; 08-18-2022 at 07:49 PM. Reason: Found additional improvements, undo customisation
Reply With Quote