Log in

View Full Version : Powerpoint Form - How to generate a GUID in a Powerpoint Form



dturnell
08-01-2017, 08:34 AM
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

John Wilson
08-02-2017, 08:17 AM
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"

Paul_Hossler
08-02-2017, 01:21 PM
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

John Wilson
08-03-2017, 02:00 AM
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