Option Explicit
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type FILETIME
dummy As Currency
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Sub Command1_Click()
Debug.Print AlmostUniqueID
End Sub
' Only almost unique, because of the actual clock resolution on current platforms is either about 10ms or 15ms
' which means it is possible to get the same value back if we make the calls too close to each other
' Note that this is also true of the Ticks value
Private Function AlmostUniqueID() As String
Dim sysTime As SYSTEMTIME
Dim fTime As FILETIME
GetSystemTime sysTime
SystemTimeToFileTime sysTime, fTime
AlmostUniqueID = Right(String(14, "0") & fTime.dummy, 14)
End Function