Hello tvainisi,
Here is how to correctly generate the GUID (Globally Unique Identifier) or CLSID (Class ID). Place this code in its own module in your VBA project.
'Written: October 12, 2009
'Author: Leith Ross
'Summary: Function creates a GUID (aka CLSID) and returns it as a string.
Private Type GUID
Data1 As Long
Data2 As Long
Data3 As Long
Data4(8) As Byte
End Type
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
Because this is a UDF (User Defined Function) you can place it in cell to return a new GUID to the cell.
Bookmarks