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 :)

Re: Insert superscripted ordinal date - Word 2000 ?? by Jean-Guy

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



Re: Insert superscripted ordinal date - Word 2000 ?? by insert

insert
Fri May 18 12:54:40 CDT 2007

Wow :)

Jean-Guy - you're a star :D

That's fantastic - thank you!

I'm not sure I completely follow what's happening there so I'm going to
dig out those VBA programmers guides to make sense of it!

Again: thank you :D

Jean-Guy Marcil wrote:
> 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
> '_______________________________________
>

Re: Insert superscripted ordinal date - Word 2000 ?? by Jean-Guy

Jean-Guy
Fri May 18 13:13:21 CDT 2007

insert your name here was telling us:
insert your name here nous racontait que :

> Wow :)
>
> Jean-Guy - you're a star :D
>
> That's fantastic - thank you!
>
> I'm not sure I completely follow what's happening there so I'm going
> to dig out those VBA programmers guides to make sense of it!
>

Place the cursor at the top of the document;
Open the VBA editing window;
Size and position both windows (Document and VBA so that they both take the
width of the screen, but are on top of each other);
Click inside the VBA sub;
Hit F8 to debug line by line.

This way you will see what each line does (as long as it does something
visible in the document!).

I always do that when I debug, I find it helps me see what is going on...
Sometimes, I even add a
.Select
statement inside a

With rgeDate

End With

block (where rgeDate represents a range). This way I see what is happening
to my range as the code progresses. When I am done, I remove those ".Select"
statements because they are not necessary. This is the beauty of the Range
object, you can manipulate a document that is even invisible!

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Insert superscripted ordinal date - Word 2000 ?? by Perry

Perry
Fri May 18 20:46:50 CDT 2007

Once in a while, you have to give credits to persons dealing with VBA
problems.
It's not about technical ability, it's about what OP asked, and what has
been offered as solution.
It's about dedication!

(sheer acknowledgement)
Cheers and good work, JGM !!!!
--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



"Jean-Guy Marcil" <DontEvenTry@NoSpam> schreef in bericht
news:ulVX7gXmHHA.3520@TK2MSFTNGP04.phx.gbl...
> insert your name here was telling us:
> insert your name here nous racontait que :
>
>> Wow :)
>>
>> Jean-Guy - you're a star :D
>>
>> That's fantastic - thank you!
>>
>> I'm not sure I completely follow what's happening there so I'm going
>> to dig out those VBA programmers guides to make sense of it!
>>
>
> Place the cursor at the top of the document;
> Open the VBA editing window;
> Size and position both windows (Document and VBA so that they both take
> the width of the screen, but are on top of each other);
> Click inside the VBA sub;
> Hit F8 to debug line by line.
>
> This way you will see what each line does (as long as it does something
> visible in the document!).
>
> I always do that when I debug, I find it helps me see what is going on...
> Sometimes, I even add a
> .Select
> statement inside a
>
> With rgeDate
>
> End With
>
> block (where rgeDate represents a range). This way I see what is happening
> to my range as the code progresses. When I am done, I remove those
> ".Select" statements because they are not necessary. This is the beauty of
> the Range object, you can manipulate a document that is even invisible!
>
> --
>
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>


Re: Insert superscripted ordinal date - Word 2000 ?? by Jean-Guy

Jean-Guy
Sat May 19 11:45:46 CDT 2007

Perry was telling us:
Perry nous racontait que :

> Once in a while, you have to give credits to persons dealing with VBA
> problems.
> It's not about technical ability, it's about what OP asked, and what
> has been offered as solution.
> It's about dedication!
>
> (sheer acknowledgement)
> Cheers and good work, JGM !!!!

Thanks, but you're pretty dedicated yourself!

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org