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
Shellwithin 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,
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:
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.
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
- Did you try to change command
Application.Quit? Maybe that’s a difference when starting from command line.
I use Excel 2007 on Win XP Pro.