• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

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?
0
pwanveer
Asked:
pwanveer
  • 3
1 Solution
 
Mark_FreeSoftwareCommented:
read this:
(both vb6 and .net)
http://www.buygold.net/v01n01/v01n01.html

direct downloadlink to (vb6) the source:
http://www.buygold.net/v01n01/guid.zip

direct downloadling to .net source:
http://www.buygold.net/v01n01/guidvb7.zip
0
 
Mark_FreeSoftwareCommented:

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), ByVal StrPtr(res), 128)
    CreateGUID = Left$(res, resLen - 1)
End Function
0
 
jimbobmcgeeCommented:
Or, more simply:

    Set oTypeLib = CreateObject("Scriptlet.TypeLib")
    szMyGuid = oTypeLib.Guid
    '...
    Set oTypeLib = Nothing
   
HTH

J.
0
 
pwanveerAuthor Commented:
A quick download of the Class Module and a quick code edit and I'm done! You are a rockstar! Thank you.
0
 
Mark_FreeSoftwareCommented:


thanx for the points and happy coding!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now