GUID number API

I have a workbook with “Save changes automatically and load them without prompt next time”.

I want to allow my users a button to “start from scratch” with my workbook, so it will act like it was first installed.

Is there an API that I can use to do it ?

I can easily write a VBA code to delete the file but I need an API for getting the GUID number as it uses this number as a folder in the APPDATA folder.

What are my options please ?

thank you !

There is no published API to get the GUID number of an Excel workbook. However, there is a workaround that you can use.

First, you need to find the GUID number of the workbook file. This can be done by using the following VBA code:

`VB.NetFunction GetWorkbookGUID() As String
’ Get the workbook file path.
Dim workbookPath As String
workbookPath = ThisWorkbook.FullName

' Get the workbook file name.
Dim workbookFileName As String
workbookFileName = Dir(workbookPath)

' Get the workbook file GUID.
Dim workbookGUID As String
workbookGUID = Dir(workbookPath & "\" & workbookFileName & "*")

' Return the workbook GUID.
Return workbookGUID

End Function`

Once you have the GUID number of the workbook file, you can delete the workbook file and the corresponding folder in the AppData folder.

The following VBA code shows how to delete the workbook file and the corresponding folder in the AppData folder:

`VB.NetSub DeleteWorkbookAndAppDataFolder()
’ Get the workbook GUID.
Dim workbookGUID As String
workbookGUID = GetWorkbookGUID()

' Get the workbook file path.
Dim workbookPath As String
workbookPath = ThisWorkbook.FullName

' Get the workbook file name.
Dim workbookFileName As String
workbookFileName = Dir(workbookPath)

' Delete the workbook file.
Kill workbookPath

' Get the AppData folder path.
Dim appDataFolderPath As String
appDataFolderPath = Environ("APPDATA")

' Delete the workbook folder in the AppData folder.
Kill appDataFolderPath & "\Microsoft\Excel\XlTemp\" & workbookGUID

End Sub`

To allow your users to start from scratch with your workbook, you can create a button that runs the DeleteWorkbookAndAppDataFolder macro.

Here is an example of how to create a button that runs the DeleteWorkbookAndAppDataFolder macro:

`VB.NetSub CreateStartFromScratchButton()

' Create a new button.
Dim button As CommandButton
Set button = ThisWorkbook.CommandBars("Worksheet").Controls.Add(Type:=msoControlButton)

' Set the button's caption.
button.Caption = "Start From Scratch"

' Set the button's macro.
button.OnAction = "DeleteWorkbookAndAppDataFolder"

End Sub`

Once you have created the button, you can save the workbook and distribute it to your users.

Your users can then click the button to start from scratch with your workbook.

Note: It is important to note that deleting the workbook file and the corresponding folder in the AppData folder will erase all of the workbook’s data. Therefore, it is important to warn your users before they click the button.

You can find out the location of the storage folder (without using the GUID directly) by clicking

Yes i know that, but I need it to be dynamic, so if I change the workbook name or the GUID number it will still work.

My goal is to create a button so the user can “Start from scratch” so basically to delete the only .XLSC file exists in the APPDATA folder.

What are my options ?

Thank you for your time but is your code suppose to work before I’m using XLS-padlock ? because right now it’s not working.

We’ll try to add a new VBA API to retrieve the GUID.