save and delete a file when in it with code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to be able to kill a file once I have saved a copy of it to it's new
location.

I can save a copy from within the file and I can kill it from my desktop
(executing the same code) . When I go to kill from within the folder I get a
Permission Denied (Error 70) appearing. I am the owner / creator of the
folders and have full control of them. I can delete anything with mouse
clicks but not with code from within the folder.
The code I am using is as follows:

Sub DeletethenSaveFile()

Folderdetails = " Filepath and Name"

ThisWorkbook.SaveCopyAs "New Filepath and Name"
MsgBox "Your file has been saved to it's new location"

On Error Resume Next
Kill Folderdetails '"Filepath and Name"
MsgBox "The requested file has been deleted"
MsgBox "This file will now close"
ThisWorkbook.Close SaveChanges = False


End Sub

Please help me!!! D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top