Article ID: 182431
Article Last Modified on 7/13/2007
23rd day of February, 1994
March 21st, 1994
Tuesday the 15th, 1994
Sub GetOrdinalDates()
Dim fDate As FormField
' If no documents are open or if no form fields
' exist in the active document, or for other
' errors, exit this routine.
On Error GoTo errhandler
' Replace the word Date with the name of your
' form field with your formfield bookmark name.
Set fDate = ActiveDocument.FormFields("Date")
' Is the result of the form field a valid date?
If Not IsDate(fDate.Result) Then Exit Sub
' Determine date format.
Select Case Day(fDate.Result)
Case 1, 21, 31
daysuffix$ = Day(fDate.Result) & "st"
Case 2, 22
daysuffix$ = Day(fDate.Result) & "nd"
Case 3, 23
daysuffix$ = Day(fDate.Result) & "rd"
Case Else
daysuffix$ = Day(fDate.Result) & "th"
End Select
' Use ONE of the following formats.
' (Remove the remark (apostrophe) from the
' command lines that produce the desired format.)
' - Format example: 24th day of February, 1998
' fDate.Result = daysuffix$ & " day of " _
' & Format$(fDate.Result, "mmmm, yyyy")
' - Format example: February 24th, 1998
' fDate.Result = Format$(fDate.Result, "mmmm") & " " & _
' daysuffix$ & Format$(fDate.Result, ", yyyy")
' - Format example: Tuesday the 24th, 1998
' fDate.Result = Format$(fDate.Result, "dddd") & " the " & _
' daysuffix$ & Format$(fDate.Result, ", yyyy")
errhandler:
End Sub
For additional information, please see the following article in the
Microsoft Knowledge Base:
181058 OFF98: How to Run Sample Code from Knowledge Base Articles
117267 WD: How to Create Ordinal (Legal) Date Formatting in FORM Fields
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vba vbe
Keywords: kbcode kbdtacode kbhowto kbmacroexample kbprogramming KB182431