How to get the time stamp in VBA for EXCEL

  • Thread starter Thread starter Ji Wenke
  • Start date Start date
J

Ji Wenke

I want to record current time (Hour-Minutes-Second) in
VBA.How to accomplish with VB code,use what system
function call
 
Hi Ji,
Try this,

Sub TimeStamper()
Range("A1").Value = Now
Range("A1").NumberFormat = "H:MM AM/PM"
End Sub

Regards, Rocky McKinley
 
I want to record current time (Hour-Minutes-Second) in
VBA.How to accomplish with VB code,use what system
function call

I probably misunderstand the question, but doesn't:
Hour(Now) & "-" & Minute(Now) & "-" & Second(Now)
work for you?
(Nit pick: the above might give unexpected results when its execution
straddles midnight.)
 
Hi Ji,
Oops should have included ":SS" as below,

Sub TimeStamper()
Range("A1").Value = Now
Range("A1").NumberFormat = "H:MM:SS AM/PM"
End Sub

Regards, Rocky McKinley
 
Back
Top