Hi all,
I have a Workbook that imports a large text file, then sorts out the info I want. The info I want is then saved as a new text file. I then import the new text file and do a little more extraction and save the final worksheet as a new Workbook. This is all done in one macro & the Excel application is never closed. The file opened by excel changes from .xls to .txt then finally to .xls.
The problem: After I close Excel, I still have an invisible Excel Application showing in my Task Manager. As a result when I try to delete the .xls saved on my Desktop, it tells me it can't be deleted because it is still in use. I can end this process manually in Task Manager, but I want to be able to do it within my macro.
So here are the relevant parts of my code:
I have a Workbook that imports a large text file, then sorts out the info I want. The info I want is then saved as a new text file. I then import the new text file and do a little more extraction and save the final worksheet as a new Workbook. This is all done in one macro & the Excel application is never closed. The file opened by excel changes from .xls to .txt then finally to .xls.
The problem: After I close Excel, I still have an invisible Excel Application showing in my Task Manager. As a result when I try to delete the .xls saved on my Desktop, it tells me it can't be deleted because it is still in use. I can end this process manually in Task Manager, but I want to be able to do it within my macro.
So here are the relevant parts of my code:
Code:
'Import text file & sort
'save workbook as text file
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\" & (Environ("UserName")) & "\Desktop\RScaliper.txt", FileFormat:=xlText _
, CreateBackup:=False
'import the new text file
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\sriling\Desktop\RScaliper.txt", Destination _
...
...
End With
'delete xtra worksheets & save as .xls
Application.DisplayAlerts = False
Sheets(1).Delete
Sheets(1).Delete
Sheets(1).Delete
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\" & (Environ("UserName")) & "\Desktop\RScaliper.xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
'delete the new text file - not needed anymore
Kill "C:\Documents and Settings\" & (Environ("UserName")) & "\Desktop\RScaliper.txt"