Option Explicit
Public Function CreateGUID(Optional IncludeHyphens As Boolean = True, _
Optional IncludeBraces As Boolean = False) _
As String
Dim obj As Object
Dim strGUID As String
Set obj = CreateObject("Scriptlet.TypeLib")
'Assign the raw GUID, minus the last two erroneous chars
strGUID = Left(obj.GUID, Len(obj.GUID) - 2)
'If IncludeHyphens is switched from the default True to False,
'remove them from the GUID
If Not IncludeHyphens Then
strGUID = Replace(strGUID, "-", vbNullString, Compare:=vbTextCompare)
End If
'If IncludeBraces is switched from the default False to True,
'leave those curly braces be!
If Not IncludeBraces Then
strGUID = Replace(strGUID, "{", vbNullString, Compare:=vbTextCompare)
strGUID = Replace(strGUID, "}", vbNullString, Compare:=vbTextCompare)
End If
CreateGUID = strGUID
End Function
Sub Test()
Dim GUID As String
On Error Resume Next
GUID = CreateGUID() '<~ default
If ActiveCell.Column <> 2 Then
'ActiveCell.Offset(0, 18).Value = ""
Exit Sub
Else
If ActiveCell.Offset(0, -1) <> "" Then
ActiveCell.Offset(0, 18).Value = GUID
End If
End If
End Sub