Kill statement problems

  • Thread starter Thread starter Marino13
  • Start date Start date
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
 
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
 
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
 
Back
Top