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

Page 1 of 2 12 LastLast

  1. Posts : 11
    Windows 7 32 and 64 bit (dual boot)
       #1

    "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:
    Last edited by JohnSmithWin7; 25 Jan 2017 at 06:24.
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    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 Computer


  3. Posts : 11
    Windows 7 32 and 64 bit (dual boot)
    Thread Starter
       #3

    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.
    Last edited by JohnSmithWin7; 26 Jan 2017 at 14:12. Reason: wrong answer
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    Sorry, this is a PowerShell command.

    How to Open Windows PowerShell in Windows 7
      My Computer


  5. Posts : 11
    Windows 7 32 and 64 bit (dual boot)
    Thread Starter
       #5

    Unfortunately I don't have PowerShell installed.
      My Computer


  6. Posts : 7,107
    W7 home premium 32bit/W7HP 64bit/w10 tp insider ring
       #6

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

    Roy
      My Computer


  7. Posts : 11
    Windows 7 32 and 64 bit (dual boot)
    Thread Starter
       #7

    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 Attached Thumbnails &quot;The server threw an exception error&quot; when running Excel-to-CSV.Vbs-capture.jpg  
      My Computer


  8. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #8

    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 Computer


  9. Posts : 11
    Windows 7 32 and 64 bit (dual boot)
    Thread Starter
       #9

    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.

    Last edited by JohnSmithWin7; 27 Jan 2017 at 09:46.
      My Computer


  10. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #10

    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.


    JohnSmithWin7 said:
    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 Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 04:03.
Find Us