Create UUID


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'**********************************************************************************************************
' Name:                 createUUID
' Author:               mielk | 2014-12-11
'
' Comment:              Function returns the path to the Desktop folder.
'
' Returns:
'   String              The full access path to the Desktop folder.
'
'
' Exceptions:
'   CreatingObjectException         Thrown if it was impossible to create an instance of Scriptlet.typeLib
'                                   object.
'
' --- Changes log -----------------------------------------------------------------------------------------
' 2014-12-11        mielk       Function created.
'**********************************************************************************************************
Public Function createUUID() As String
    Const METHOD_NAME As String = "createUUID"
    '------------------------------------------------------------------------------------------------------
    Const LIBRARY_NAME As String = "Scriptlet.TypeLib"
    '------------------------------------------------------------------------------------------------------
    Dim typeLib As Object
    '------------------------------------------------------------------------------------------------------


    'Create a new instance of Scriptlet.TypeLib object --------------------------------------------------|
    On Error GoTo CreatingObjectException                                                               '|
    Set typeLib = VBA.CreateObject(LIBRARY_NAME)                                                        '|
    On Error GoTo 0                                                                                     '|
    '----------------------------------------------------------------------------------------------------|


    'If shell object has been properly created, use it to obtain Desktop folder path. -------------------|
    If Not typeLib Is Nothing Then                                                                      '|
        createUUID = VBA.Mid$(typeLib.GUID, 2, 36)                                                      '|
    End If                                                                                              '|
    '----------------------------------------------------------------------------------------------------|



'==========================================================================================================
ExitPoint:
    Set typeLib = Nothing
    Exit Function


'----------------------------------------------------------------------------------------------------------
CreatingObjectException:
    'Error handler for the case if it was impossible to create an instance of Scriptlet.TypeLib object.
    GoTo ExitPoint


End Function