Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1820to1824
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

VBA soll Excel schließen

VBA soll Excel schließen
25.03.2021 10:24:36
Daniel
Hallo zusammen,
habe folgendes laufen. Leider wird die Datei nur geschlossen, aber nicht das Excel so das immer Excel, ohne geöffnete Datei, offen bleibt. Kann Excel direkt mit beendet werden? Aktuell habe ich ein Taskkill.bat immer laufen die Excel hart beendet.
Modul:
Public Const ciIntervall As Integer = 1
Public Const dsMacro As String = "AutoClose"
Public gdNextTime As Double
Private iWait As Integer
Const cMax = 10 ' -> 10 Sekunden
Dim Zeit As Date
Sub AutoClose()
iWait = iWait + 1
If cMax - iWait > 0 Then
Application.StatusBar = Format(Zeit - TimeSerial(0, 0, iWait), "hh:mm:ss")
gdNextTime = Now + TimeSerial(0, 0, ciIntervall)
Application.OnTime gdNextTime, dsMacro
Else
ThisWorkbook.Save
ThisWorkbook.Close
End If
End Sub
Sub AutoCloseStart()
iWait = 0
Zeit = TimeSerial(0, 0, cMax)
Application.StatusBar = Zeit
Call AutoClose
End Sub
Sub AutoCloseStop()
On Error Resume Next
Application.StatusBar = ""
Application.OnTime earliesttime:=gdNextTime, _
procedure:=dsMacro, schedule:=False
End Sub
Diese Arbeitsmappe

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Call AutoCloseStop
End Sub


Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
AutoCloseStop
AutoCloseStart
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
AutoCloseStop
AutoCloseStart
End Sub


Private Sub Workbook_WindowActivate(ByVal Wn As Window)
AutoCloseStop
AutoCloseStart
End Sub


Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
AutoCloseStop
AutoCloseStart
End Sub


4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: VBA soll Excel schließen
25.03.2021 10:26:57
mumpel
Application.Quit

AW: VBA soll Excel schließen
25.03.2021 10:36:05
Daniel
An welche Stelle muss das Application.Quit?

AW: VBA soll Excel schließen
25.03.2021 19:49:09
mumpel
Sub AutoClose()

iWait = iWait + 1

  If cMax - iWait > 0 Then
     Application.StatusBar = Format(Zeit - TimeSerial(0, 0, iWait), "hh:mm:ss")
     gdNextTime = Now + TimeSerial(0, 0, ciIntervall)
     Application.OnTime gdNextTime, dsMacro
  Else
     ThisWorkbook.Save
     Application.Quit
  End If

End Sub

VBA/HTML-CodeConverter, AddIn für Excel 2002-2019 (32-bit) und Excel 365 (32-bit Desktop-Version)
In VBA geschrieben von Lukas Mosimann. Projektbetreuung: René Holtz


Code erstellt und getestet in Excel 365 32-bit Desktopversion
Codedarstellung mit VBAHTML 12.6.0 erstellt.



Anzeige
AW: VBA soll Excel schließen
26.03.2021 13:08:44
Daniel
Super, Danke.

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige