Anwendungsfehler bei Application.quit
07.01.2005 10:42:22
Andreas
ich habe eine Excel-Arbeitsmappe, die als Formular genutzt werden soll. Diese wird per Link im Internet-Explorer geöffnet. Die Mappe enthält auch aktiven VBA-Code.
Wenn nun im Explorer das Fenster geschlossen oder z.B. die Zurück Schaltfläche betätigt wird, so bleibt die Excel-Anwendung unsichtbar im Hintergrund aktiv, obwohl die Arbeitsmappe dabei geschlossen wird. Daher möchte ich gerne die Excel-Anwendung beenden, wenn die Arbeitsmappe geschlossen wird. Dazu habe ich folgenden Code im Klassenmodul der Arbeitsmappe erstellt:
Option Explicit
Dim calcmode As Variant
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim savemode As Boolean
Dim wb As Workbook
savemode = ThisWorkbook.Saved
If IsEmpty(calcmode) Then
Application.Calculation = xlCalculationAutomatic
Else
Application.Calculation = calcmode
End If
ThisWorkbook.Saved = savemode
If Not Application.Visible Then
For Each wb In Workbooks
If wb.Name <> Me.Name Then wb.Close savechanges:=False
Next
set wb = Nothing
Application.Quit
End
End If
End Sub
Bei Application.Quit stürzt Excel mit einer Fehlermeldung ab "Excel.exe Fehler in Anwendung..."
Wie bekomme ich die Excel-Application sauber aus dem Speicher, wenn diese vom IE geöffnet wurde?
Viele Grüße,
Andreas