View Single Post
 
Old 07-24-2011, 08:44 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Hi areriff,

You could name the Content Control 'Mydate' add the following code to the document's 'This Document' module:
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
    If .ShowingPlaceholderText Then Exit Sub
    .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
        .Type = wdContentControlDate
        Exit For
      End If
    Next
  End If
End With
End Sub
 
Function Ordinal(Val As Integer) As String
Dim strOrd As String
If (Val Mod 100) < 11 Or (Val Mod 100) > 13 Then strOrd = Choose(Val Mod 10, "st", "nd", "rd") & ""
Ordinal = IIf(strOrd = "", "th", strOrd)
End Function
Of course, you might prefer to use something more meaningful than 'MyDate' for the Content Control name ...

For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote