JennaWashburn
New Member
- Joined
- Aug 3, 2020
- Messages
- 6
- Office Version
- 2016
- Platform
- Windows
I have the following code that works great for a .xlsm file:
But when I use a compiler and change my file to a .exe it does not work anymore. My goal is to have the file deleted from the computer entirely. I am not sure why this isn't working...I also found this snippet of code (which is also not working):
Any help is greatly appreciated!
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With ThisWorkbook
If Len(Dir(.FullName)) Then
.Saved = True
On Error Resume Next
.ChangeFileAccess Mode:=xlReadOnly
On Error GoTo 0
SetAttr .FullName, vbNormal
Kill .FullName
Application.Quit
End If
End With
End Sub
But when I use a compiler and change my file to a .exe it does not work anymore. My goal is to have the file deleted from the computer entirely. I am not sure why this isn't working...I also found this snippet of code (which is also not working):
VBA Code:
Sub DeleteActiveWorkbook()
Dim xFullName As String
xFullName = Application.ActiveWorkbook.FullName
ActiveWorkbook.Saved = True
Application.ActiveWorkbook.ChangeFileAccess xlReadOnly
Kill xFullName
Application.ActiveWorkbook.Close False
End Sub
Any help is greatly appreciated!