Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript converts xls to txt but the txt files are still open in Excel and cannot be deleted 3

Status
Not open for further replies.

rcrecelius

Technical User
Mar 13, 2003
108
US
Forgive me, I dont know vbs, I searched and searched for what I have so far and feel like I am very close to a solution on this.

All files are in the same folder, currently on my laptop.
The task at hand is...

1.Take 3 xls files and convert them to txt
2.Combine the txt files into a single file - I've got a simple batch file handling this
3.Load the combined txt file into my ERP system(Epicor Vision) -
4.Then the cleanup part of this would be to delete the xls and txt files before the next time we run this process, which would likely be done on a weekly basis.

Mr Google led me to this solution for converting the xls to txt, which works great BUT, when I try to delete the txt files, I get the message that "The action cannot be completed because the file is open in Excel".
Or if I try to delete at command line I get "The process cannot access the file because it is being used by another process."

I think all I am missing is something to close Excel but I have searched for a while and have yet to find something that works with this.
My script...
Code:
Set ExcelObject = CreateObject("Excel.Application")
ExcelObject.Visible = False
Set wb = ExcelObject.Workbooks.Open("C:\csv_combine\FUTURE_900_INCREASE_CODING.xls")
wb.SaveAs "C:\csv_combine\FUTURE 900 INCREASE CODING .txt", -4158
Set wb = ExcelObject.Workbooks.Open("C:\csv_combine\FUTURE_004_INCREASE_CODING.xls")
wb.SaveAs "C:\csv_combine\FUTURE 004 INCREASE CODING .txt", -4158
Set wb = ExcelObject.Workbooks.Open("C:\csv_combine\FUTURE_901_INCREASE_CODING.xls")
wb.SaveAs "C:\csv_combine\FUTURE 901 INCREASE CODING .txt", -4158


Thanks in advance for all the your forthcoming brilliance!
 
After doing your SaveAs to make text files,
Do a final SaveAs to save as an Excel file.

Now you can delete your text files.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Afrer each [tt]Wb.SaveAs[/tt] execute [tt]Wb.Close[/tt], otherwise the workbook pointing to text file stays open in excel.

combo
 
Is the excel object closed before the script exits?

Code:
ExcelObject.Quit
set ExcelObject=Nothing

Check task manager - how many excel instances are there running when the script exits?
 
Thank you gentlemen, stars for all of you!

xwb said:
Check task manager - how many excel instances are there running when the script exits?
XWB, to answer your question, there was a single instance of Excel open in task mgr after running the script.


After exploring the options/suggestions, this is what I ended up with, which seems to do what I need.

Code:
Set ExcelObject = CreateObject("Excel.Application")
ExcelObject.Visible = False
Set wb = ExcelObject.Workbooks.Open("C:\csv_combine\FUTURE_900_INCREASE_CODING.xls")
wb.SaveAs "C:\csv_combine\FUTURE 900 INCREASE CODING.txt", -4158
Wb.Close SaveChanges = False 
Set wb = ExcelObject.Workbooks.Open("C:\csv_combine\FUTURE_004_INCREASE_CODING.xls")
wb.SaveAs "C:\csv_combine\FUTURE 004 INCREASE CODING.txt", -4158
Wb.Close SaveChanges = False
Set wb = ExcelObject.Workbooks.Open("C:\csv_combine\FUTURE_901_INCREASE_CODING.xls")
wb.SaveAs "C:\csv_combine\FUTURE 901 INCREASE CODING.txt", -4158
Wb.Close SaveChanges = False

Thanks again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top