Home » excel » windows – Why does Excel throw an exception on Quit when started from command line?

windows – Why does Excel throw an exception on Quit when started from command line?

Posted by: admin May 14, 2020 Leave a comment


I have a simple Excel file that queries a database when it opens and then closes automatically.

  • If I double click the file to open it from within Windows Explorer (I’m running Windows XP and Excel 2002), it works fine.
  • However, if I run it using Excel "C:\DataUpdate.xls" from Start > Run or from Shell within another instance of Excel in a separate file, Excel will crash on exit.

I can’t figure out why it does it one scenario and not in the other.

In DataUpdate.xls, I have 2 procedures, UpdateTable() and OnWorkbookOpen(), which is called from Workbook_Open() when the workbook opens.

Option Explicit

Sub UpdateTable()

Dim ws As Worksheet
Dim qt As QueryTable

Set ws = Worksheets("Sheet1")
Set qt = ws.Range("A1").QueryTable

qt.Refresh BackgroundQuery:=False

End Sub

Sub OnWorkbookOpen()
On Error Resume Next
If ActiveWorkbook.Name = "DataUpdate.xls" Then
'I put this If statement in so I can change the file's
'name and then edit the file without code


End If

End Sub

If I open the file from Windows Explorer, everything is fine. If I run it from the command line with Excel "C:\DataUpdate.xls", the code runs fine until the application tries to exit with Application.Quit, at which point Excel throws an exception.

When I view the details of the error report, here’s some of the information I find:

AppName: excel.exe
AppVer: 10.0.6854.0
ModName: olconnector.dll
ModVer: 2.0.2303.0
Offset: 000114d5

Why is there different behavior based on how I start the application and what can I do so that the application behaves the same regardless of how I start it?

How to&Answers:

According to google olconnector.dll is outlook connector, an office add-in.


Since it is dealing with Outlook, I believe it would have some dependency on the login you are using on the machine.

When you are opening excel, are you using the same credentials as the account you log in to the computer with?

ProcessStartInfo startInfo = null;
Process batchProcess = null;

startInfo = new ProcessStartInfo();
startInfo.Domain = "somedomain";
startInfo.UserName = "Domainuser";
startInfo.Password = "pwd";

Not really sure on what the error is, but this is something you could try out.


When I only put command application.quit into function Workbook_Open() it works fine here, when I start it via doubleclick, via command test.xlsm as well as via command "c:\Programme\Microsoft Office\Office12\EXCEL.EXE" test.xlsm.

  • Did you also try to reduce the problem to only that one command?
  • Which command do you use from command line.
  • Maybe you can try putting DoEvents after Application.Save command?
  • Did you try to change command Excel.Application.Quit to Application.Quit? Maybe that’s a difference when starting from command line.

I use Excel 2007 on Win XP Pro.