Kill Function will not delete the file

lnagel

Board Regular
Joined
May 28, 2018
Messages
117
Looks fairly simple - Code runs just like it knows what to do and then nothing

File resides on Desktop and .Fullname does return the correct path

Code:
tempFileName = targetWorkbook.FullName
    'MsgBox "Target Workbook Name = " & tempFileName
    targetWorkbook.Save
    targetWorkbook.Close
    Kill tempFileName

I have also tried to close the workbook using the workbooks.close method - same results

Ideas?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Do you get an error, or does it just do nothing?

As an aside, why save it if you're going to delete it?
 
Upvote 0
What error do you get if you omit the save?
 
Upvote 0
ooops Not correct - I get errors if I omit the close... I have tried both with and without the save.... both ways produce the same result (Nothing). However I get the Save Dialog Box if I dont do the save in the code
 
Upvote 0
If you don't get errors, it should be deleting something, assuming you haven't got On Error Resume Next shoved in there somewhere.

Try this:

Code:
tempFileName = targetWorkbook.FullName
    'MsgBox "Target Workbook Name = " & tempFileName
    targetWorkbook.Close False
    doevents
    Kill tempFileName
 
Upvote 0
so sent the workbook to work this morning - getting the same results on a different PC and Excel version... Don't have any On Error Resume Next in the code... Have also tried to do a Dlete via the FSO route - Same result doesnt work... I'm stumped
 
Upvote 0
Targetworkbook isn’t the workbook with the code in it, I assume?
 
Upvote 0
Hmmm.... so I have stumbled across a few threads where they were trying to create self kill routines . Having said that... I am trying to kill a copy of the workbook that I am running the code from that has been named something different.

So I end manipulating 3 different workbooks with one of those being a copy of the calling workbook.

You may have hit on the problem...

I will look at code in the morning to verify that what I think is running is actually running.

Great stab at this... the more I think iabout it..... the more likely it seems that you may be right.
 
Upvote 0
Add a Msgbox statement after the line that closes the workbook and see if you see the message.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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