Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5501
  • Last Modified:

creating a GUID in excel

Hello All-
I want to generate in a cell a GUID for the excel file. However, it cannot change every time you open/ close it. It would be a once and done deal. So re opening it to make some edits, keeps the GUID the same.

It has to do with SSIS package I built, and in order for the DB to update the already imported fields, I need something unique that won't change each time you open the file up on the client side.

Any Ideas...Thanx
0
BKennedy2008
Asked:
BKennedy2008
  • 2
1 Solution
 
tipsybroomCommented:
try this:

Public Sub TestGetGUID() 
    MsgBox GetGUID, vbInformation, "GUID Generated" 
End Sub 
 
Public Function GetGUID() As String 
    GetGUID = Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36) 
End Function 

Open in new window


or this:

Public Type TYP_GUID
            bytes(15) As Byte
End Type
 
Public Declare Function CoCreateGuid Lib "OLE32.dll" _
                       (Guid As TYP_GUID) As Long
Public Declare Function StringFromGUID2 Lib "OLE32.dll" _
                       (Guid As TYP_GUID, _
                        ByVal lpszString As String, _
                        ByVal iMax As Long) As Long
 
Public Function CreateGUID() As String

    Dim uGuid   As TYP_GUID
    Dim sBuffer As String
    Dim lResult As Long
 
    sBuffer = VBA.Space(78)
    CoCreateGuid uGuid
    lResult = StringFromGUID2(uGuid, sBuffer, Len(sBuffer))
    CreateGUID = _
    Left$(StrConv(sBuffer, vbFromUnicode), lResult - 1)
 
End Function

Open in new window

0
 
BKennedy2008Author Commented:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Q_22542230.html

I found pretty much exactly what I was looking for here, but thanks tips
0
 
BKennedy2008Author Commented:
found in another spot
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now