2009年7月18日 星期六

Macro for TimeStamps

link:

code :

Sub MacroTimeStamps_Click()
ActiveCell.FormulaR1C1 = TimeInMS()
Range(ColNo2ColRef(ActiveCell.Column) & "65536").End(xlUp).Offset(1).Select
End Sub

Public Function TimeInMS() As String
'TimeInMS = Strings.Format(Now, "dd-MMM-yyyy HH:nn:ss") & "." & Strings.Right(Strings.Format(Timer, "#0.00"), 2)
TimeInMS = Strings.Format(Now, "HHnnss")
End Function

Function ColNo2ColRef(ColNo As Integer) As String
'converts a column number between 1 and 256 to a column reference (A - IV):
If ColNo <> 256 Then
ColNo2ColRef = "#VALUE!"
Exit Function
End If
ColNo2ColRef = Cells(1, ColNo).Address(True, False, xlA1)
ColNo2ColRef = Left(ColNo2ColRef, InStr(1, ColNo2ColRef, "$") - 1)
End Function

Function ColRef2ColNo(ColRef As String) As Integer
'converts a column reference (A - IV) to a column number between 1 and 256:
ColRef2ColNo = 0
On Error Resume Next
ColRef2ColNo = Range(ColRef & "1").Column
End Function

沒有留言:

張貼留言