VBA - Undo save, i.e. delete a file that has just been saved and open original.

NiceToMichu

New Member
Joined
Nov 17, 2015
Messages
2
Hi guys,

These are my Subs:

Sub Undosave()

Application.ScreenUpdating = False
Application.OnTime Now, "Undosave2"
ThisWorkbook.Close SaveChanges:=False

End Sub
Sub Undosave2()

Application.Workbooks.Open ("C:\Users\Seth\Documents\Costing Program\Process Costing\Process Costing Updating")
Windows("C:\Users\Seth\Documents\Costing Program\Process Costing\Process Costing Updating").Activate
Kill ("C:\Users\Seth\Documents\Costing Program\Process Costing\" & Range("K37").Value)
MsgBox "Deleted"
Application.ScreenUpdating = True

End Sub

I am basically trying to delete a file that has just been 'saved as' and then reopen the original from where the 'save as' was orignally created. Now the name of the 'saved as' file is made up from the file directory & one of the cell values "K37", I have tried multiple times but the error message pops-up and says it either can't find the file or file is out of range. Please help!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
unless you have backups turned on, when you delete a file you change a control bit in the disk structure and hide it from the operating system. I don't believe that excel can operate like that to find a deleted file and undelete, its what the recycle bin tries to do, and there are commercial packages to scan for accidentally deleted files to enable a recovery
 
Upvote 0
Thanks for the reply @mole999, I think I explained my predicament quite poorly so sorry for that! I need to undo a saveas by deleting the file that was created :)
 
Last edited:
Upvote 0
just a guess, you may need to re-read the directory, so that the extraneous file is found, then issue a kill for it. How best to do this, I'm not sure
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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