views:

229

answers:

2

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
'running.

    UpdateTable
    ActiveWorkbook.Save

    Excel.Application.Quit
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?

A: 

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.

Marco
- I just tried limiting it to just application.quit. Didn't work.- From cmd: EXCEL.EXE "C:\DataUpdate.xls"- Putting DoEvents after Application.Quit did not work- I changed it to Application.Quit - did not work
Ben McCormack
+3  A: 

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

http://ask.officelive.com/workspace/qna/t/4578.aspx

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.

OG
I'll be darned if it wasn't the Office Live Add-in that was causing the problem! +1 for the link and thanks for the tip. I never would have thought something that obscure would have been the cause of the problem.
Ben McCormack
Uninstalling the Office Live Add-in v1.3 fixed the problem.
Ben McCormack