Kuba
Kuba

Reputation: 13

Converting already opened XLS to CSV

I have VBscript code which opens XLS file and export it to CSV, see below:

Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open("test.xls")
oBook.SaveAs "test.csv", 6
oBook.Close False
oExcel.Quit

It works fine but I need to do the same - convert XLS to CSV with already opened file "test.xls" on my computer which is different (edited by me) versus saved version. Is that possible?

Upvotes: 1

Views: 68

Answers (1)

Michael
Michael

Reputation: 4838

Yes, you just need to connect the existing instance of Excel and set workbook object variable equal to the already open workbook instead:

Set oExcel = GetObject(, "Excel.Application")
Set oBook = oExcel.Workbooks("test.xls")

Upvotes: 2

Related Questions