Consulting

Results 1 to 4 of 4

Thread: Powerpoint Form - How to generate a GUID in a Powerpoint Form

  1. #1
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    1
    Location

    Powerpoint Form - How to generate a GUID in a Powerpoint Form

    Hi, I have created a simple form in Powerpoint where users will fill in data in a couple of fields in the slide show view.

    I have included a Submit button that will send the completed slide to an end user.

    I am trying to figure out how to generate a unique number or ID for each form that is filled in. I found code from Excel that I am trying to adapt to PPT, but being a VBA novice, I am having a really hard time.

    Thank all in advance for help!

    Debra

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    The code from Excel probably doesn't work now after recent updates if it includes code like CreateObject("Scriptlet.TypeLib"). You are likely to get a permission denied error as it seems MSFT have decided it is "unsafe"
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Try this



    Option Explicit
    
    Private Declare PtrSafe Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As LongPtr
    
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type
    
    Sub drv()
        MsgBox CreateGUID
    End Sub
    
    '           111 1111 1112 222222222333
    '{12345678-9012-3456-7890-123456789012)
    '{000204EF-0000-0000-C000-000000000046}
    Public Function CreateGUID() As String
        Dim G As GUID
        Dim s As String
        With G
            If (CoCreateGuid(G) = 0) Then
                s = _
                    String$(8 - Len(Hex$(.Data1)), "0") & Hex$(.Data1) & _
                    String$(4 - Len(Hex$(.Data2)), "0") & Hex$(.Data2) & _
                    String$(4 - Len(Hex$(.Data3)), "0") & Hex$(.Data3) & _
                    IIf((.Data4(0) < &H10), "0", vbNullString) & Hex$(.Data4(0)) & _
                    IIf((.Data4(1) < &H10), "0", vbNullString) & Hex$(.Data4(1)) & _
                    IIf((.Data4(2) < &H10), "0", vbNullString) & Hex$(.Data4(2)) & _
                    IIf((.Data4(3) < &H10), "0", vbNullString) & Hex$(.Data4(3)) & _
                    IIf((.Data4(4) < &H10), "0", vbNullString) & Hex$(.Data4(4)) & _
                    IIf((.Data4(5) < &H10), "0", vbNullString) & Hex$(.Data4(5)) & _
                    IIf((.Data4(6) < &H10), "0", vbNullString) & Hex$(.Data4(6)) & _
                    IIf((.Data4(7) < &H10), "0", vbNullString) & Hex$(.Data4(7))
                CreateGUID = "{" & Mid(s, 1, 8) & "-" & Mid(s, 9, 4) & "-" & Mid(s, 13, 4) & "-" & Mid(s, 17, 4) & "-" & Mid(s, 21, 12) & "}"
            
            
            End If
        End With
    End Function
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    That works well Paul. I was told it wouldn't work in 64 bit Office but it does. I suspect they had the declaration incorrect!

    As declared it will not run in 2007 or earlier.

    Option Explicit
    #If VBA7 Then
       Declare PtrSafe Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As LongPtr
    #Else
       Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
    #End If
    Private Type GUID
       Data1 As Long
       Data2 As Integer
       Data3 As Integer
       Data4(0 To 7) As Byte
    End Type
    Last edited by John Wilson; 08-03-2017 at 03:21 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •