Kill statement problems

M

Marino13

When I run this code;

Sub Newe()
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs ("The File.xls")
.SendMail Recipients:="(e-mail address removed)", Subject:= _
"Your file"
Kill .FullName
.Close False
End With
End Sub

I am getting an error message that says:

Run-Time error '75':
Path/File access error

The debugger highlights the Kill .FullName line of my code.
What's wrong with this
 
B

Boicie

Using the Kill command that way, you are trying to delete a workboo
that is open. Which is not possible.

You'll need to close it first, then delete it which can be achieve
using the following code which stores the file path into variable 'x
and changes two of your lines of code around to close it first, the
deletes the file indicated by 'x'.


Sub Newe()
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs ("The File.xls")
.SendMail Recipients:="(e-mail address removed)", Subject:= _
"Your file"

x = .FullName
.Close False
Kill x

End With
End Sub



Regards,

Boici
 
J

John Wilson

Boicie,
you are trying to delete a workbook
that is open. Which is not possible.

Nothing is impossible.
From a previous post by Chip Pearson:

With ThisWorkbook
.Saved = True
.ChangeFileAccess xlReadOnly
Kill.FullName
.Close savechanges:=False
End With

John
 

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

Top