View Single Post
  #9   Report Post  
Graham Mayor
 
Posts: n/a
Default

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.