Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Inserting date/time in certain format?
I put the icons for date and time, which are separate, onto my toolbar
yesterday. But I got a "2005-02-10" and "1:30 PM" result. I need to customize to a toolbar icon something like this instead: "2005.02.10.Th., 13h30" which is format we use at office. Is there any way to do this? Or perhaps a macro that I can attach to a toolbar? Any ideas? Thanks much! D |
#2
|
|||
|
|||
If you could live with the standard day abbreviations you could use:
Sub DateStamp2() ' Inserts current date Dim timeStr As String timeStr = Format(Date, "yyyy.mm.dd.ddd") & "., " & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub Otherwise you would need a pretty complicated IF expression to convert say Fri to Fr, Sun to Su, etc. |
#3
|
|||
|
|||
Hmm - you could set up a DATE field with the Date-Time picture you want,
save it as AutoText and put that on the toolbar. But you'd need to select and press Ctrl-Shift-F9 or Ctrl-6 to stop it updating to the current date when you open the document again. Or you could write a one-line macro using the InsertDateTime method - something like Selection.InsertDateTime _ DateTimeFormat:="yyyy'.'MM'.'dd'.'ddd'.,' HH'h'mm", InsertAsField:=False I don't believe you can get the Th abbreviation - ddd gives you three letters. (See Help topic for Date Time picture.) -- Margaret Aldis - Microsoft Word MVP Syntagma partnership site: http://www.syntagma.co.uk Word MVP FAQ site: http://www.word.mvps.org "StargateFan" wrote in message ... I put the icons for date and time, which are separate, onto my toolbar yesterday. But I got a "2005-02-10" and "1:30 PM" result. I need to customize to a toolbar icon something like this instead: "2005.02.10.Th., 13h30" which is format we use at office. Is there any way to do this? Or perhaps a macro that I can attach to a toolbar? Any ideas? Thanks much! D |
#4
|
|||
|
|||
Not that complicated
Sub DateStamp2() ' Inserts current date Dim timeStr, dayStr As String dayStr = Left(Format(Date, "ddd"), 2) timeStr = Format(Date, "yyyy.mm.dd.") & dayStr & "., " _ & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Greg wrote: If you could live with the standard day abbreviations you could use: Sub DateStamp2() ' Inserts current date Dim timeStr As String timeStr = Format(Date, "yyyy.mm.dd.ddd") & "., " & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub Otherwise you would need a pretty complicated IF expression to convert say Fri to Fr, Sun to Su, etc. |
#5
|
|||
|
|||
See http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm for help in
constructing a field to your requirements. You'll doubtless need a concatenation of several fields, and, as Margaret pointed out, your abbreviation for the day of the week is not supported by Word. When you have arrived at a string of fields that works, you can save it as an AutoText entry. Note that you probably don't want a Date field but more likely CreateDate. Note that the Date and Time fields by default use the default short or long date format you have defined in Windows Control Panel | Regional Options. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "StargateFan" wrote in message ... I put the icons for date and time, which are separate, onto my toolbar yesterday. But I got a "2005-02-10" and "1:30 PM" result. I need to customize to a toolbar icon something like this instead: "2005.02.10.Th., 13h30" which is format we use at office. Is there any way to do this? Or perhaps a macro that I can attach to a toolbar? Any ideas? Thanks much! D |
#6
|
|||
|
|||
Clever boy :-)
|
#7
|
|||
|
|||
On Fri, 11 Feb 2005 16:45:13 +0200, "Graham Mayor"
wrote: Not that complicated Sub DateStamp2() ' Inserts current date Dim timeStr, dayStr As String dayStr = Left(Format(Date, "ddd"), 2) timeStr = Format(Date, "yyyy.mm.dd.") & dayStr & "., " _ & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub EXCELLENT! I had to play a bit with some spaces as the ng puts breaks in long lines g, but got the code working! I knew this could be done. I have the same non-standard format in Excel from vba coding also so kindly given to me but about a year ago or more now. There is only one thing I would change, if it's possible? Can we have leading zero for the time? i.e., my freeware systray clock showed 23h09 a few moments ago. The time portion of this Word macro, however, writes out the same time as 23h9 instead of 23h09, so no leading zero in the minutes. Also, if in the a.m., would need format like 02h02 instead of 2h2 so that, in other words, the hours also have a leading zero. Can this excellent code above be modified to reflect that? Thanks much! http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Greg wrote: If you could live with the standard day abbreviations you could use: Sub DateStamp2() ' Inserts current date Dim timeStr As String timeStr = Format(Date, "yyyy.mm.dd.ddd") & "., " & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub Otherwise you would need a pretty complicated IF expression to convert say Fri to Fr, Sun to Su, etc. |
#8
|
|||
|
|||
On Fri, 11 Feb 2005 08:56:36 -0600, "Suzanne S. Barnhill"
wrote: See http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm for help in constructing a field to your requirements. You'll doubtless need a concatenation of several fields, and, as Margaret pointed out, your abbreviation for the day of the week is not supported by Word. When you have arrived at a string of fields that works, you can save it as an AutoText entry. Note that you probably don't want a Date field but more likely CreateDate. Note that the Date and Time fields by default use the default short or long date format you have defined in Windows Control Panel | Regional Options. Graham Mayor very kindly provided a simple yet elegant code to do just that g. This time format is non-standard in Excel, also, yet I have code to do this very same thing. Granted, code is vastly different than the one Graham provided, but it does the same job. That's why I knew it would be impossible. g Cheers! D -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "StargateFan" wrote in message .. . I put the icons for date and time, which are separate, onto my toolbar yesterday. But I got a "2005-02-10" and "1:30 PM" result. I need to customize to a toolbar icon something like this instead: "2005.02.10.Th., 13h30" which is format we use at office. Is there any way to do this? Or perhaps a macro that I can attach to a toolbar? Any ideas? Thanks much! D |
#9
|
|||
|
|||
am hours should be OK as it stands. For the minutes you need to add a second
'n' to the time mask ie Sub DateStamp2() ' Inserts current date Dim timeStr, dayStr As String dayStr = Left(Format(Date, "ddd"), 2) timeStr = Format(Date, "yyyy.mm.dd.") & dayStr & "., " _ & Format(Time, "HH") & "h" & Format(Time, "nn") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org StargateFan wrote: On Fri, 11 Feb 2005 16:45:13 +0200, "Graham Mayor" wrote: Not that complicated Sub DateStamp2() ' Inserts current date Dim timeStr, dayStr As String dayStr = Left(Format(Date, "ddd"), 2) timeStr = Format(Date, "yyyy.mm.dd.") & dayStr & "., " _ & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub EXCELLENT! I had to play a bit with some spaces as the ng puts breaks in long lines g, but got the code working! I knew this could be done. I have the same non-standard format in Excel from vba coding also so kindly given to me but about a year ago or more now. There is only one thing I would change, if it's possible? Can we have leading zero for the time? i.e., my freeware systray clock showed 23h09 a few moments ago. The time portion of this Word macro, however, writes out the same time as 23h9 instead of 23h09, so no leading zero in the minutes. Also, if in the a.m., would need format like 02h02 instead of 2h2 so that, in other words, the hours also have a leading zero. Can this excellent code above be modified to reflect that? Thanks much! http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Greg wrote: If you could live with the standard day abbreviations you could use: Sub DateStamp2() ' Inserts current date Dim timeStr As String timeStr = Format(Date, "yyyy.mm.dd.ddd") & "., " & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub Otherwise you would need a pretty complicated IF expression to convert say Fri to Fr, Sun to Su, etc. |
#10
|
|||
|
|||
On Fri, 11 Feb 2005 23:16:13 -0500, StargateFan
wrote: On Fri, 11 Feb 2005 08:56:36 -0600, "Suzanne S. Barnhill" wrote: See http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm for help in constructing a field to your requirements. You'll doubtless need a concatenation of several fields, and, as Margaret pointed out, your abbreviation for the day of the week is not supported by Word. When you have arrived at a string of fields that works, you can save it as an AutoText entry. Note that you probably don't want a Date field but more likely CreateDate. Note that the Date and Time fields by default use the default short or long date format you have defined in Windows Control Panel | Regional Options. Graham Mayor very kindly provided a simple yet elegant code to do just that g. This time format is non-standard in Excel, also, yet I have code to do this very same thing. Granted, code is vastly different than the one Graham provided, but it does the same job. That's why I knew it would be impossible. g g ... That should read "knew it would be POSSIBLE ... lol [snip] |
#11
|
|||
|
|||
I figured you meant it would be impossible for *you* (but possible thanks to
Graham). g -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "StargateFan" wrote in message ... On Fri, 11 Feb 2005 23:16:13 -0500, StargateFan wrote: On Fri, 11 Feb 2005 08:56:36 -0600, "Suzanne S. Barnhill" wrote: See http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm for help in constructing a field to your requirements. You'll doubtless need a concatenation of several fields, and, as Margaret pointed out, your abbreviation for the day of the week is not supported by Word. When you have arrived at a string of fields that works, you can save it as an AutoText entry. Note that you probably don't want a Date field but more likely CreateDate. Note that the Date and Time fields by default use the default short or long date format you have defined in Windows Control Panel | Regional Options. Graham Mayor very kindly provided a simple yet elegant code to do just that g. This time format is non-standard in Excel, also, yet I have code to do this very same thing. Granted, code is vastly different than the one Graham provided, but it does the same job. That's why I knew it would be impossible. g g ... That should read "knew it would be POSSIBLE ... lol [snip] |
#12
|
|||
|
|||
On Sat, 12 Feb 2005 11:06:00 -0600, "Suzanne S. Barnhill"
wrote: I figured you meant it would be impossible for *you* (but possible thanks to Graham). g lol -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "StargateFan" wrote in message .. . On Fri, 11 Feb 2005 23:16:13 -0500, StargateFan wrote: On Fri, 11 Feb 2005 08:56:36 -0600, "Suzanne S. Barnhill" wrote: See http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm for help in constructing a field to your requirements. You'll doubtless need a concatenation of several fields, and, as Margaret pointed out, your abbreviation for the day of the week is not supported by Word. When you have arrived at a string of fields that works, you can save it as an AutoText entry. Note that you probably don't want a Date field but more likely CreateDate. Note that the Date and Time fields by default use the default short or long date format you have defined in Windows Control Panel | Regional Options. Graham Mayor very kindly provided a simple yet elegant code to do just that g. This time format is non-standard in Excel, also, yet I have code to do this very same thing. Granted, code is vastly different than the one Graham provided, but it does the same job. That's why I knew it would be impossible. g g ... That should read "knew it would be POSSIBLE ... lol [snip] |
#13
|
|||
|
|||
On Fri, 11 Feb 2005 23:13:55 -0500, StargateFan
wrote: On Fri, 11 Feb 2005 16:45:13 +0200, "Graham Mayor" wrote: Not that complicated Sub DateStamp2() ' Inserts current date Dim timeStr, dayStr As String dayStr = Left(Format(Date, "ddd"), 2) timeStr = Format(Date, "yyyy.mm.dd.") & dayStr & "., " _ & Format(Time, "HH") & "h" & Format(Time, "n") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub [snip] There is only one thing I would change, if it's possible? Can we have leading zero for the time? i.e., my freeware systray clock showed 23h09 a few moments ago. The time portion of this Word macro, however, writes out the same time as 23h9 instead of 23h09, so no leading zero in the minutes. Also, if in the a.m., would need format like 02h02 instead of 2h2 so that, in other words, the hours also have a leading zero. Can this excellent code above be modified to reflect that? Any way to get two leading zeros? Cheers. |
#14
|
|||
|
|||
StargateFan wrote:
Any way to get two leading zeros? *Two* leading zeros? You can get any layout you want by applying varations to the format included in the code. Where do you want the two zeros and under what circumstances do you want the extra ones? The revised code I posted earlier will match your original request for one leading zero where appropriate. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#15
|
|||
|
|||
On Sun, 13 Feb 2005 07:43:10 +0200, "Graham Mayor"
wrote: StargateFan wrote: Any way to get two leading zeros? *Two* leading zeros? You can get any layout you want by applying varations to the format included in the code. Where do you want the two zeros and under what circumstances do you want the extra ones? The revised code I posted earlier will match your original request for one leading zero where appropriate. Darn, must have missed a post. I'll see if re-dl headers will bring it back. Re two leading zeros, one for hours and one for minutes, i.e., instead of 2h2 (for 2 a.m. and 2 minutes), 02h02. Thanks. I'll go look for the extra post. Agent must have missed it somehow even though thread being watched. Cheers! |
#16
|
|||
|
|||
On Sat, 12 Feb 2005 08:17:01 +0200, "Graham Mayor"
wrote: am hours should be OK as it stands. For the minutes you need to add a second 'n' to the time mask ie Sub DateStamp2() ' Inserts current date Dim timeStr, dayStr As String dayStr = Left(Format(Date, "ddd"), 2) timeStr = Format(Date, "yyyy.mm.dd.") & dayStr & "., " _ & Format(Time, "HH") & "h" & Format(Time, "nn") & " " Selection.InsertBefore (timeStr) Selection.Collapse Direction:=wdCollapseEnd End Sub Ah, here it is! Yes, that seems to be working just fine. I've made the change you advise by putting the extra "n" in the time format part. Thank you! This little macro is going to make life much easier. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Outline Format Conversion | Formatting Long Documents | |||
Preserve Formatting of TOC | Microsoft Word Help | |||
mail merge from excel that changes my format from UK to US format | Mailmerge | |||
Is there a template for a research paper in APA format? | Microsoft Word Help | |||
Maintaining the format of linked tables. | Tables |