VB and VBA Users Source Code: Create a GUID
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Create a GUID
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, July 04, 2000
Hits:
1389
Category:
Windows API
Article:
If you have ever wanted to create your own globally unique identifer, then use the following code: Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGUID As GUID) As Long Private Declare Function StringFromGUID2 Lib "OLE32.DLL" (pGUID As GUID, ByVal PointerToString As Long, ByVal MaxLength As Long) As Long Private Type GUID Guid1 As Long Guid2 As Long Guid3 As Long Guid4(0 To 7) As Byte End Type Public Function CreateGUID() As String Dim udtGUID As GUID Dim sGUID As String Dim lResult As Long Const clGuidLength As Long = 38 lResult = CoCreateGuid(udtGUID) If lResult Then sGUID = "" Else sGUID = String$(clGuidLength, 0) StringFromGUID2 udtGUID, StrPtr(sGUID), clGuidLength + 1 End If CreateGUID = sGUID End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder