Declare Function CoCreateGuid Lib "ole32" (id As Any) As Long
CoCreateGuid создает GUID - уникальный идентификатор, используемый в CLSID.
При успешном создании GUID возвращается S_OK, в случае ошибки возвращается ненулевое значение.
' Получим уникальный GUID
Public Function CreateGUID() As String
Dim id(0 To 15) As Byte
Dim Cnt As Long, GUID As String
If CoCreateGuid(id(0)) = 0 Then
For Cnt = 0 To 15
CreateGUID = CreateGUID + IIf(id(Cnt) < 16, "0", "") + Hex$(id(Cnt))
Next Cnt
CreateGUID = Left$(CreateGUID, 8) + "-" + Mid$(CreateGUID, 9, 4) + "-" + _
Mid$(CreateGUID, 13, 4) + "-" + Mid$(CreateGUID, 17, 4) + "-" + Right$(CreateGUID, 12)
Else
MsgBox "Error while creating GUID!"
End If
End Function
Private Sub Command1_Click()
MsgBox CreateGUID
End Sub