Kill file

McCrunch

New Member
Joined
Jan 13, 2010
Messages
6
Hi,
I've got a sheet that I need to convert certain rows into CSV for a payroll package. I'm using excel 2003 on XP.

I have worked out a macro to save it as a csv file with a different name. The only way I managed to do this was by creating an xls file with the data I wanted and then saving it as a csv file with a different name. But now I need to delete the intermediate xls file (called pre CSV in this example). I have the following code which seemed to work first time but is now giving me the error "Runtime error 53 - File not found" and highlights the Kill filename command. What am I doing wrong?

Code:
Sub Direct()
    Workbooks.Add
    ActiveWorkbook.SaveAs filename:=CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Pre CSV.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
     Windows("Commission calc.xls").Activate
    Range("I3:M500").Select
    Selection.Copy
    Windows("Pre CSV.xls").Activate
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Application.CutCopyMode = False
 
ActiveWorkbook.SaveAs filename:=CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Broker comm dir.csv", FileFormat _
:=xlCSV, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
 
Dim filename As String
filename = "Pre CSV"
Kill filename
End Sub

Thanks
 
Last edited:
Thanks Mark. Both of those work well and quickly. Like the idea being able to save straight to a CSV file as well. Once again thanks all for making my excel life easier.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,480
Messages
6,125,049
Members
449,206
Latest member
Healthydogs

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