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?
Thanks
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: