Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Apr 2010
    Location
    Hampshire
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Guys,

    First time here - loving the breadth and depth of knowledge on display.

    I am hoping that someone may offer some assistance to a relative novice at this kind of thing - I have read Macropod's brilliant date/time document, and it has answered a lot of my questions but......

    I am trying to create a Text Form Field in a Word 2007 Document that will accept a user input date (which won't get subsequently updated - but doesn't need to be locked) and I would like the date to be formatted including the ordinal for the day -

    eg - 27th July 2010

    I can get to the stage where the input is displayed as '27 July 2010' - where I am pulling my hair out is getting the 'th' dropped in there.

    In the Text Form Field Options box I have tried appending the \* Ordinal switch after the d - eg d \* Ordinal MMMM YYYY but this doesn't work - I have tried a number of different alternatives, either with or without the curly brackets but nothing seems to work.

    I really don't want to resort to VB and Macros - I can't help thinking there is a simple solution which I am somehow missing.

    Thanks, in advance, for any suggestions,

    Nigel

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,898
    Thanks
    0
    Thanked 188 Times in 172 Posts
    Hi Nigel,

    With your text formfield, you could mandate a simple 8-digit entry, in the form of DDMMYYYY, then use the following 'MakeOrdinalDate' macro as the formfield's 'on exit' macro:
    Code:
    Sub MakeOrdinalDate()
    With ActiveDocument.FormFields(Selection.Range.Bookmarks(1).Name)
      If Len(.Result) = 8 Then _
        If IsDate(Left(.Result, 2) & "/" & Mid(.Result, 3, 2) & "/" & Right(.Result, 4)) Then _
          .Result = OrdinalNumber(Left(.Result, 2)) & " " & Format(CDate(Left(.Result, 2) & "/" & Mid(.Result, 3, 2) & "/" & Right(.Result, 4)), "MMMM YYYY")
    End With
    End Sub
    
    Function OrdinalNumber(ByVal Num As Long) As String
    Dim N As Long
    N = Num Mod 100
    If ((Abs(N) > 10) And (Abs(N) < 14)) Or ((Abs(N) Mod 10) > 3) Or ((Abs(N) Mod 10) = 0) Then
      OrdinalNumber = Format(Num, "0") & Format(Abs(N), "t\h")
    Else
      OrdinalNumber = Format(Num, "0") & Format(Abs(N) Mod 10 - 2, "r\d;\st;\n\d")
    End If
    End Function
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •