1st, 2nd, 3rd, 4th etc

F

Francis Hookham

A macro has the following line

Selection.InsertDateTime DateTimeFormat:="d MMMM yyyy", InsertAsField:=
_
False, DateLanguage:=wdEnglishUK, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False

Is there anyway of automatically adding ordinals with superscript?

1st, 2nd, 3rd... 11th... 21st...

Sounds like a tall order but someone might have sorted it out

Francis Hookham
 
D

Daiya Mitchell

And there seems to be an explanation at the bottom of this page:
http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm
(hit refresh a few times in Safari, or use a different browser)

I'm not completely sure how it will work with the macro, though...as those
are fields and I would think you would need a field to use a switch, I'm not
sure just adding the switch to the text within quotations marks would work.

Experiment some.

The first thing that occurs to me would be to use a macro to 1) insert a
field (possibly via AutoText), then 2) to promptly Unlink the field to
convert it to straight text. Or it might be possible to insert a field that
is set to locked, I don't know.

Possibly someone else has truly sorted it out and will post.

Alternatively, depending on how you use this insert date macro--it might
work for you to use a CreateDate field or a SaveDate field to get the
appropriate date instead.

Hope that helps,
Daiya
 
J

JE McGimpsey

One way:

This is hardly efficient, and has zero error checking, but it's worked
for me for years, and I've never felt the need to change it:

Public Sub InsertOrdinalizedDate()
Dim a As String
Dim nDay As Long
nDay = Day(Date)
With Selection
.InsertAfter nDay
.Collapse wdCollapseEnd
.InsertAfter Ordinal(nDay)
.Font.Superscript = True
.Collapse wdCollapseEnd
.InsertAfter Format(Date, " MMMM yyyy")
.Font.Superscript = False
.Collapse wdCollapseEnd
End With
End Sub

Public Function Ordinal(ByVal n As Long) As String
Const sSUFFIXES As String = "stndrdthththththth"
n = Abs(n)
If (n Mod 10 = 0) Or ((n > 3) And (n < 20)) Then
Ordinal = "th"
Else
Ordinal = Mid(sSUFFIXES, (n Mod 10) * 2 - 1, 2)
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top