We help IT Professionals succeed at work.

Can Excel or VB create GUIDs?

pwanveer
pwanveer asked
on
Medium Priority
322 Views
Last Modified: 2010-04-07
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?
Comment
Watch Question

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

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
Or, more simply:

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

J.

Author

Commented:
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!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.