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 fromShellwithin 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?
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?
Not really sure on what the error is, but this is something you could try out.