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