Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joehanna
Created March 23, 2015 00:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joehanna/4eaa64d8e34e9d8e2646 to your computer and use it in GitHub Desktop.
Save joehanna/4eaa64d8e34e9d8e2646 to your computer and use it in GitHub Desktop.
Generate a GUID from VBA or VBScript
Function GenGuid() As String
Dim TypeLib As Object
Dim guid As String
Dim guid2 As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
guid = Left$(TypeLib.guid, 38)
Set TypeLib = Nothing
' format is {24DD18D4-C902-497F-A64B-28B2FA741661}
guid = Replace(guid, "{", "")
guid = Replace(guid, "}", "")
'Guid = Replace(Guid, "-", "")
'Return result
GenGuid = guid
End Function
@neilt17
Copy link

neilt17 commented Aug 9, 2017

As of Office Security updates - July 2017 - this is likely to give a permission denied error. An alternative method is given in this Stack Overflow question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment