Solved

creating a GUID in excel

Posted on 2012-03-22
3
4,121 Views
Last Modified: 2012-04-01
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
Comment
Question by:BKennedy2008
  • 2
3 Comments
 
LVL 7

Expert Comment

by:tipsybroom
ID: 37754159
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
 

Accepted Solution

by:
BKennedy2008 earned 0 total points
ID: 37754363
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
 

Author Closing Comment

by:BKennedy2008
ID: 37792672
found in another spot
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

803 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