pwanveer
asked on
Can Excel or VB create GUIDs?
I have an application I am building in Excel which I believe will be migrated to SQL or Access in the future. I am using Worksheets as Tables and need to assign unique ID's in a number of places. I would like to use GUIDs from inception so as to simplify the migration process as much as possible. Can Excel of VBA auto create GUIDs?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Or, more simply:
Set oTypeLib = CreateObject("Scriptlet.Ty peLib")
szMyGuid = oTypeLib.Guid
'...
Set oTypeLib = Nothing
HTH
J.
Set oTypeLib = CreateObject("Scriptlet.Ty
szMyGuid = oTypeLib.Guid
'...
Set oTypeLib = Nothing
HTH
J.
ASKER
A quick download of the Class Module and a quick code edit and I'm done! You are a rockstar! Thank you.
thanx for the points and happy coding!
or if you don't feel like checking that, use this code:
Declare Function CoCreateGuid_Alt Lib "OLE32.DLL" Alias "CoCreateGuid" (pGuid _
As Any) As Long
Declare Function StringFromGUID2_Alt Lib "OLE32.DLL" Alias "StringFromGUID2" _
(pGuid As Any, ByVal address As Long, ByVal Max As Long) As Long
Function CreateGUID() As String
Dim res As String, resLen As Long, guid(15) As Byte
res = Space$(128)
CoCreateGuid_Alt guid(0)
resLen = StringFromGUID2_Alt(guid(0
CreateGUID = Left$(res, resLen - 1)
End Function