Jean-Guy
Fri May 18 12:44:09 CDT 2007
insert your name here was telling us:
insert your name here nous racontait que :
> Hi all :)
>
> I'm trying to create a macro that inserts the current date to replace
> the selected text (not as a field).
>
> ------------------
> Selection.InsertDateTime DateTimeFormat:="dd MMMM yyyy",
> InsertAsField:= False, DateLanguage:=wdEnglishUK,
> CalendarType:=wdCalendarWestern, InsertAsFullWidth:=False
> ------------------
>
> is easy enough and gives me the date as 18 May 2007 but I need to
> insert it as 18th May 2007 with the ordinal (st,nd,rd) in superscript.
>
> I think that it's something to do with \* ordinal but I can't for the
> life of me work out how the syntax goes. And I can't even begin to
> guess how to do the superscripting!
>
> Yes, I know it's a silly way of formatting a date - it wasn't my idea
> ;)
> Thanks all :)
The problem here is to make the two characters superscript automatically.
Normally Word does that as part of its AutoCorrect as you type feature. When
you insert text with VBA, this does not come into play, so you have to do it
yourself.
Without the superscript, you would only need to add two fields next to each
other like this:
{DATE \@ d \*Ordinal} {DATE \@ "MMMM YYYY"}
or have this set up as an AutoText, insert the AutoText and then unlink the
fields to convert them to text.
However, this will not make the "st," "nd," "rd" or "th" superscript.
Right now I cannot think of a switch in a field that would do that, there
maybe one, but I am not seeing it now.
In code, you can try the following. It is a bit complicated but it works.
There is probably a simpler way to do this, but that it my problem... I
always overcode... probably because I like coding!
'_______________________________________
Dim rgeDate As Range
Set rgeDate = Selection.Range
With rgeDate
.Fields.Add rgeDate, wdFieldEmpty, "DATE \@ """ & "d" & """ \* \ordinal"
.MoveEnd wdWord, 1
.Fields(1).Unlink
.MoveStart wdCharacter, Len(.Text) - 2
.Font.Superscript = True
.Collapse wdCollapseEnd
.InsertAfter " "
.Font.Superscript = False
.Collapse wdCollapseEnd
.Fields.Add rgeDate, wdFieldEmpty, "DATE \@ """ & "MMMM YYYY" & """"
.MoveEnd wdWord, 1
.Fields(1).Unlink
.Next.Words(1).Select
End With
Selection.Collapse wdCollapseEnd
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site:
http://www.word.mvps.org