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.