Deleting a .exe file

JennaWashburn

New Member
Joined
Aug 3, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
I have the following code that works great for a .xlsm file:

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!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How exactly are you trying to do this (xlsm to exe)?
Are you using some sort of program?

From what I have read, it looks like you need some sort of special program to do that, i.e. Excel To Exe converter
Note that I am not necessarily endorsing that product. I have never used it myself. They are others you can find with a Google search. Some may be free, and others not.
 
Upvote 0
Yeah I am using DoneEx but it isn’t executing that code on workbook_close anymore....

but if I specify the path name it works. It just won’t work using the .FullName method
 
Upvote 0
I really don't have any experience with that program, so I cannot tell what does and doesn't work with it.
I don't know if they have a help/support feature, but you may want to look into that.

I did find some conversations on using these types of programs. Here are a few:

Hope that those are helpful.
 
Upvote 0
Jenna

I got a feeling this might not return the name and path for the .exe file
VBA Code:
xFullName = Application.ActiveWorkbook.FullName

Try adding code that shows you what xFullName actually is, recompile and see what happens.
VBA Code:
MsgBox xFullName
 
Upvote 0
Jenna

I got a feeling this might not return the name and path for the .exe file
VBA Code:
xFullName = Application.ActiveWorkbook.FullName

Try adding code that shows you what xFullName actually is, recompile and see what happens.
VBA Code:
MsgBox xFullName

Yes, you are right, it is adding random letter/numbers to the path....hmmm I am not sure how to fix that, I think I may need to manipulate some settings in the compiler?
 
Upvote 0
Jenna

Don't you know the name of the .exe file?

I would have thought that providing a name for the output/target file would be a prerequisite when compiling.
 
Upvote 0
Jenna

Don't you know the name of the .exe file?

I would have thought that providing a name for the output/target file would be a prerequisite when compiling.
Yes, I know the name of the file but the compiler I am using adds random letters to the file path....I asked the company if it is possible to compile without changing the path. However, when I just write the path out it does kill the file. When I send the file to different people I will not know the exact file path which is why I was using the .FullName method.
 
Upvote 0
Yes, you are right, it is adding random letter/numbers to the path....hmmm I am not sure how to fix that, I think I may need to manipulate some settings in the compiler?

So I looked into this more....when I compile the workbook it basically creates a backend Excel sheet and a separate application. The code I used then deletes the backend excel sheet. Is there a way to get the name of the application file path, like you would with the .FullName function? Maybe something like
VBA Code:
Application.ThisApplication.FullName

I know that is probably not right but hoping someone knows the real answer.
 
Upvote 0

Forum statistics

Threads
1,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top