Time format

  • Thread starter Thread starter George M. Lutz
  • Start date Start date
G

George M. Lutz

How do I change the format for the time? I wrote a "TimeStamp" macor
that inserts 8:23 AM into the text, but I want it to be 8:23 am.

Thanks.

George Lutz
 
Shauna:

The entire macro is:


Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False

Thanks for the heldp.

George Lutz
 
Hi George

I would have thought that "h:mm am/pm" should format the time as, eg, "11.40
am", but it doesn't. However the Format() function does seem to work as
advertised, so we can get the system time using the Time() function, and
format it using the Format() function.

Your original macro will insert the date (albeit with the wrong format) and
replace any currently selected content. If you accidentally ran the macro
with lots of text selected, you would get what might be called 'unexpected
results'! So it's wise to collapse the selection before you insert the date.

Here's a macro that will collapse the selection, insert the date as, eg,
"11:45 am" and then leave the cursor at the end of the newly-inserted text.

Sub InsertDateForGeorge()
With Selection
.Collapse Direction:=wdCollapseStart
.InsertAfter Format(Time(), "h:mm am/pm")
.Collapse Direction:=wdCollapseEnd
End With
End Sub

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
Back
Top