Windows 7 Forums

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)
 
 
"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 <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

-----------------------------------------------

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 SpecsSystem Spec
.
26 Jan 2017   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 SpecsSystem Spec
26 Jan 2017   #3
JohnSmithWin7

Windows 7 32 and 64 bit (dual boot)
 
 

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 SpecsSystem Spec
.

26 Jan 2017   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Sorry, this is a PowerShell command.

How to Open Windows PowerShell in Windows 7
My System SpecsSystem Spec
27 Jan 2017   #5
JohnSmithWin7

Windows 7 32 and 64 bit (dual boot)
 
 

Unfortunately I don't have PowerShell installed.
My System SpecsSystem Spec
27 Jan 2017   #6
torchwood

W7 home premium 32bit/W7HP 64bit/w10 tp insider ring
 
 

Powershell is included as part of W7,
So who removed it.

Roy
My System SpecsSystem Spec
27 Jan 2017   #7
JohnSmithWin7

Windows 7 32 and 64 bit (dual boot)
 
 

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
&quot;The server threw an exception error&quot; when running Excel-to-CSV.Vbs-capture.jpg  
My System SpecsSystem Spec
27 Jan 2017   #8
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 <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))

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 SpecsSystem Spec
27 Jan 2017   #9
JohnSmithWin7

Windows 7 32 and 64 bit (dual boot)
 
 

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 SpecsSystem Spec
27 Jan 2017   #10
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 <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))

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   Quote: Originally Posted by JohnSmithWin7 View Post
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 SpecsSystem Spec
Reply

 "The server threw an exception error" when running Excel-to-CSV.Vbs




Thread Tools




Similar help and support threads
Thread Forum
Excel ('13) - "Document not saved" error + performance issues
Hi, Issue is with an Excel document that runs a macro to report information from another data sheet: Raw data - 3MB Macro - 8MB Result file - 120MB When the macro is complete; 1. The document shows an error when trying to save (see screenshot with error) -- Black icons show within the save...
Microsoft Office
websites not loading - error on page "500 internal server error nginx"
For the last 2 days, I am not able to access all google sites and facebook.com from my windows 7 PC. When I tried to access these websites, I am getting a blank page with the error message "500 internal server error -nginx". Can you please suggest me what could be the cause for this issue and how...
Browsers & Mail
Random "Bad Pool Header" and "System Service Exception" BSODs
I have been getting these "Bad Pool Header" and "System Service Exception" BSODs for about a day now (the "Bad Pool Header" one tends to pop up more often then the other btw). I ran a registry cleaner which didn't work and ran memtest this morning and it showed that my memory was fine. The BSODs...
BSOD Help and Support
Error: "exception processing message parameters 0xc000007FEFC3E718C"
Hi. I've been getting this error message: "exception processing message parameters 0xc000007FEFC3E718C" every time I shut down or log off, accompanied by "Bad Image" messages from time to time, usually concerning davhlpr.dll. I've run the System File Checker three times, and each time it...
BSOD Help and Support
Win7 "workstation" to WinXP "server" file copy FAIL
This is driving me bonkers and I have almost no hair left. I really hope someone can help. When I attempt to copy or move a file or folder from my Win7 box to my WinXP (SP3) media server, the operation nearly always fails. Take, for example, my trying to copy the VLC Media Player folder (704...
Network & Sharing


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 20:09.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App