Can Excel or VB create GUIDs?

Posted on 2006-03-21
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?
Question by:pwanveer
    LVL 13

    Accepted Solution

    read this:
    (both vb6 and .net)

    direct downloadlink to (vb6) the source:

    direct downloadling to .net source:
    LVL 13

    Expert Comment


    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
    LVL 16

    Expert Comment

    Or, more simply:

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


    Author Comment

    A quick download of the Class Module and a quick code edit and I'm done! You are a rockstar! Thank you.
    LVL 13

    Expert Comment


    thanx for the points and happy coding!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now