Kill line not working

Billy C

Board Regular
Joined
Aug 26, 2005
Messages
52
Hi,
Can anyone tell me why the kill line is not working in this code?
the error is runtime error 53
file not found

MyPath = ActiveWorkbook.Path
ActiveWorkbook.SaveAs Filename:=MyPath & MyName
ActiveWorkbook.SendMail Recipients:="billy.cameron@networkrail.co.uk", Subject:="TS Submittal " & trimName
ActiveWorkbook.Close
Kill "MyName.xls"
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Is the file actually called "MyName.xls" or is MyName simply the variable that holds the name of the file?

If it isn't called "MyName.xls" it won't work.

Regards

Richard
 

goblin

Active Member
Joined
Apr 16, 2003
Messages
469
If MyPath = c:\temp, you are saving your file as c:\tempMyName.xls

First, you need to add a backslash between the path and the name.

Second, you need to kill the file with a full path:
Code:
MyPath = ActiveWorkbook.Path 
ActiveWorkbook.SaveAs Filename:=MyPath & "\" & MyName 
ActiveWorkbook.SendMail Recipients:="billy.cameron@networkrail.co.uk", Subject:="TS Submittal " & trimName 
ActiveWorkbook.Close 
Kill MyPath & "\" & MyName
 

Watch MrExcel Video

Forum statistics

Threads
1,118,168
Messages
5,570,645
Members
412,335
Latest member
cinciri99
Top