我在excel中使用以下VB Scrtip来生成GUID。理想情况下,我希望GUID基于不仅随机创建的日期时间。是否有修改此脚本以根据日期和时间构建GUID?
Private Type GUID
Data1 As Long
Data2 As Long
Data3 As Long
Data4(8) As Byte
Private Declare Function CoCreateGuid _
Lib "ole32.dll" _
(ByRef pGUID As GUID) As Long
Private Declare Function StringFromGUID2 _
Lib "ole32.dll" _
(ByRef rGUID As Any, _
ByVal lpstrCLSID As Long, _
ByVal cbMax As Long) As Long
Function CreateGUID() As String
Dim b() As Byte
Dim BuffSize As Long
Dim RetVal As Long
Dim MyGUID As GUID
BuffSize = 40
ReDim b(BuffSize * 2) As Byte
RetVal = CoCreateGuid(MyGUID)
RetVal = StringFromGUID2(MyGUID, VarPtr(b(0)), BuffSize)
CreateGUID = Left$(b, RetVal - 1)
End Function
非常感谢
答案 0 :(得分:0)
GUID通常具有日期/时间组件以及其他数据。如果你希望它们不是GUID,你可以组成你想要的任何字符串,但是你需要提出自己的避免冲突的方法,特别是对于真正的GUID。