Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2011, 04:11 AM
areriff areriff is offline How to custom Date Picker CC format with Ordinal and superscript it! Windows 7 64bit How to custom Date Picker CC format with Ordinal and superscript it! Office 2010 64bit
Novice
How to custom Date Picker CC format with Ordinal and superscript it!
 
Join Date: Jul 2011
Posts: 4
areriff is on a distinguished road
Question How to custom Date Picker CC format with Ordinal and superscript it!


How to configure Date Picker Content Control to display date with ordinal number?

eg. 14 July 2011
to
14th July 2011 (with correct superscript text size and positioning, can't get it to work in this post)
Reply With Quote
  #2  
Old 07-24-2011, 08:44 PM
macropod's Avatar
macropod macropod is offline How to custom Date Picker CC format with Ordinal and superscript it! Windows 7 64bit How to custom Date Picker CC format with Ordinal and superscript it! Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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
  #3  
Old 08-18-2022, 07:37 PM
Piet Bourke Piet Bourke is offline How to custom Date Picker CC format with Ordinal and superscript it! Windows 10 How to custom Date Picker CC format with Ordinal and superscript it! 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
  #4  
Old 08-20-2022, 05:33 AM
macropod's Avatar
macropod macropod is offline How to custom Date Picker CC format with Ordinal and superscript it! Windows 10 How to custom Date Picker CC format with Ordinal and superscript it! Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by Piet Bourke View Post
That code mostly works, except there's a bug that means it ruins all date pickers in the document.
I fail so see how that is possible.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-20-2022, 11:33 AM
Piet Bourke Piet Bourke is offline How to custom Date Picker CC format with Ordinal and superscript it! Windows 10 How to custom Date Picker CC format with Ordinal and superscript it! Office 2016
Novice
 
Join Date: Aug 2022
Posts: 2
Piet Bourke is on a distinguished road
Default

The original code initially changed all date pickers to rich text controls, and then attempted to change them back to date pickers once the date had been changed to an ordinal.
".Type = wdContentControlDate" needed to be moved into a later IF statement to actually do so. I also moved ".Type = wdContentControlRichText" so it would only change the relevant date pickers, but that was really just because, more than out of necessity.

To be fair, I can't see why it actually didn't work for me without the changes, I'm just happy now it does. If it makes any difference, the date I was transforming to an ordinal was formatted simply as "d", rather than the day-month-year format posed in the original question. I ran it in Office 2016, if that makes any difference.
Reply With Quote
  #6  
Old 08-21-2022, 04:28 PM
macropod's Avatar
macropod macropod is offline How to custom Date Picker CC format with Ordinal and superscript it! Windows 10 How to custom Date Picker CC format with Ordinal and superscript it! Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by Piet Bourke View Post
The original code initially changed all date pickers to rich text controls, and then attempted to change them back to date pickers once the date had been changed to an ordinal.
No, that is not how it works. As written, the code can only apply to the date-picker content control being exited, and only then if it is titled 'MyDate'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
ordinal date superscript

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to custom Date Picker CC format with Ordinal and superscript it! word 2003 date picker nashville Word 16 04-06-2012 04:12 AM
Calculations using values from date picker controls Inkarnate Word 0 06-09-2010 07:16 AM
Word 2007 date and time picker dmcohio Word 2 04-09-2010 04:13 AM
How to custom Date Picker CC format with Ordinal and superscript it! Inserting Date, formatting to superscript and subscript louq Word 1 10-22-2009 09:29 AM
Date format always interpreted as a formula Butch Jackman Excel 1 02-14-2006 11:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft