1

I need to convert an excel spreadsheet to a csv file. I would like to do the autonomously as opposed to opening it and save as manually. As I'm trying to incorporate this into a batch file I would also like to not have to install anything. I am using Excel 2007.

I've searched throughout this site and others but have been unable to come up with a complete solution yet. I found this vbs code on here from another question, so thanks to whomever got me started.

if WScript.Arguments.Count < 2 Then
WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv <xls/xlsx source file> <csv destination file>"
Wscript.Quit
End If

csv_format = 6

Set objFSO = CreateObject("Scripting.FileSystemObject")

src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))

Dim oExcel
Set oExcel = CreateObject("Excel.Application")

Dim oBook
set oBook = oExcel.WorkBooks.Open(src_file)

oBook.SaveAs dest_file, csv_format

oBook.Close False
oExcel.Quit

The issue I'm running into is on the oExcel.WorkBooks.Open(src_file). I continually get errors that it's "Unable to get the Open property of the Workbooks" error code 800A03EC.

Research into that error leads to people having issues with code on their servers, and the fixes people suggested did not work. This is not on a server, I'm trying to run it client side on a local file. I tried the script with a different excel file and it works perfectly. The difference with this one seems to be that when I open it I get the security alert from Office File Validation.

So any thoughts as to how to skip the Office File Validation warnings when opening via script?

4

0 回答 0