Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

# Windows 7: "The server threw an exception error" when running Excel-to-CSV.Vbs

 25 Jan 2017 #1 JohnSmithWin7 Windows 7 32 and 64 bit (dual boot) 11 posts "The server threw an exception error" when running Excel-to-CSV.Vbs Hi, new to the forum, I am encountering an issue that is driving me mad I cannot find a solution anywhere to fix it. I am running this script below from cmd prompt calling it with this command line: Excel-to-Csv.vbs test.xlsx test.csv (where test.xlsx is a NON-empty .xlsx file and test.csv is expected to be the output file, i.e. it is a conversion of a file from .xlsx to .csv). ----------------------------------------------------- if WScript.Arguments.Count < 2 Then WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv " 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 ----------------------------------------------- I have Excel 2007 installed on a Windows 7 Home edition - 64 bit PC. As I said, the script (used to) simply converts a .xlsx/.xls file to a .csv file, but recently it stopped working and when I run the script, I get this error message as seen in image below, I cannot understand why it comes out. Any idea how to fix this? Line: 17 Char: 1 Error:The server threw an exception Code: 80010105 Source: (null) Here is a screenshot of the error: My System Specs
 .
 26 Jan 2017 #2 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 722 posts In a house Works for me. What’s the error you get when you run this command? Code: (New-Object -ComObject Excel.Application).Workbooks.Open("C:\path\to\file.xlsx") My System Specs
 26 Jan 2017 #3 JohnSmithWin7 Windows 7 32 and 64 bit (dual boot) 11 posts tried to run the command line you proposed changing the red text with the actual directory/file, I hope I did it right, this is what I get: C:\Program Files (x86)\Console2>(New-Object -ComObject Excel.Application).Workbooks.Open("C:\AT\temp\test.xlsx") .Workbooks.Open("C:\AT\temp\test.xlsx") was unexpected at this time. My System Specs
 .
 26 Jan 2017 #4 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 722 posts In a house Sorry, this is a PowerShell command. How to Open Windows PowerShell in Windows 7 My System Specs
 27 Jan 2017 #5 JohnSmithWin7 Windows 7 32 and 64 bit (dual boot) 11 posts Unfortunately I don't have PowerShell installed. My System Specs
 27 Jan 2017 #6 torchwood W7 home premium 32bit/W7HP 64bit/w10 tp insider ring 5,531 posts Powershell is included as part of W7, So who removed it. Roy My System Specs
 27 Jan 2017 #7 JohnSmithWin7 Windows 7 32 and 64 bit (dual boot) 11 posts I am sorry, I did not know PowerShell was installed by default, I never used it before. Attached is the result of writing that command in PowerShell. Attached Thumbnails My System Specs
 27 Jan 2017 #8 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 722 posts In a house I’m unable to observe the error firsthand, thus, any suggestions here are derived from Google searches. Firstly, if you haven’t already, manually create an Excel file in a secure location such as your desktop and test the script with that. Use this VBScript instead. Code: If WScript.Arguments.Count < 2 Then WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv " 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)) Set oExcel = CreateObject("Excel.Application") oExcel.Visible = True WScript.Sleep 1200 Set oWb = oExcel.Workbooks WScript.Sleep 1200 Set oBook = oWb.Open(src_file) WScript.Sleep 1200 oBook.SaveAs dest_file, csv_format oBook.Close False oExcel.Quit Report back if you still get an error. My System Specs
 27 Jan 2017 #9 JohnSmithWin7 Windows 7 32 and 64 bit (dual boot) 11 posts Wow, this worked! (from any directory not just from desktop) Thank you so much! Just one question: previously the script just converted directly the file from .xlsx to .csv, in a nanosecond, while now: -it opens up Excel -then it opens up the input file - then it waits ~1 second, then it closes Excel. At that point the .csv has been created, no error messages. I wonder if basically the issue is that it is necessary to open first Excel? I am asking because I have found a similar issue with a Perl script I have: it used to work fine, then it started to give me an error: Win32::OLE(0.1709) error 0x80010105: "The server threw an exception" in METHOD/PROPERTYGET "Open" at C:\AT\temp\excel-matrix-writer.pl line 61 Note that this happened exactly at the same time when the above .vbs started to give the similar "The server threw an exception" error, so I think this may originate from the same problem. I resolved that issue for that Perl script by creating a .bat that contained this instruction BEFORE the Perl command line: start input.xlsx So basically Excel was started before launching the Perl command line and with this workaround it worked, no error messages. It seems you have used something similar to solve the .vbs issue subject of this thread, I do not know if you agree. I am just trying to see if I can get to the root of the problem in Windows and solve it once forever without having to resort to start-Excel-first workarounds. My System Specs
 27 Jan 2017 #10 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 722 posts In a house Good start. Just to be sure, try this code, and repeat swapping the indicated boolean value to “False”. Code: If WScript.Arguments.Count < 2 Then WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv " 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)) Set oExcel = CreateObject("Excel.Application") oExcel.Visible = True Set oWb = oExcel.Workbooks Set oBook = oWb.Open(src_file) oBook.SaveAs dest_file, csv_format oBook.Close False oExcel.Quit If after this, having Excel open prior to running the script definitely masks the problem I would reinstall the Office suite to see if that may cure the issue for good. It should not be a necessary requirement that Excel be open for this script to succeed.    Quote: Originally Posted by JohnSmithWin7 Just one question: previously the script just converted directly the file from .xlsx to .csv, in a nanosecond, while now: [...] It’s purposely slow. At this stage we’re only trying to identify the error. Don’t always expect instant automagical solutions. My System Specs