Sub Auto_Open()
Dim tmp As Boolean
MsgBox "halt"
Application.DisplayAlerts = False
If Weekday(Date) = 1 Or Weekday(Date) = 7 Then Exit Sub
If fncKompletterAblauf() Then
tmp = fncLogFile(10, 0)
Else
tmp = fncLogFile(10, 1)
End If
' ActiveWorkbook.Close savechanges:=False
' Workbooks.Close
' Application.DisplayAlerts = True
End Sub
'Lässt alles Komplett ablaufen, schreibt Fehler in ein Logfile
Function fncKompletterAblauf() As Boolean 'Start des Makros mit allen unterpunkten
'
Dim tmp As Boolean
bversand = True
tmp = fncLogFile(11, 0)
If bversand Then
If fncVariablenfuellen Then
tmp = fncLogFile(2, 0)
Else
tmp = fncLogFile(2, 1)
bversand = False
End If
End If
If bversand Then
If fncInfoHolen() Then
tmp = fncLogFile(3, 0)
Else
tmp = fncLogFile(3, 1)
bversand = False
End If
End If
If bversand Then
If fncTabelleFuellen() Then
tmp = fncLogFile(5, 0)
Else
tmp = fncLogFile(5, 1)
bversand = False
End If
End If
If bversand Then
If fncTextdateiAnlegen() Then
tmp = fncLogFile(6, 0)
Else
tmp = fncLogFile(6, 1)
bversand = False
End If
End If
If bversand Then
If fncBatchdateiAnlegen() Then
tmp = fncLogFile(7, 0)
Else
tmp = fncLogFile(7, 1)
bversand = False
End If
End If
If bversand Then
If fncBatchExeOpen() Then
tmp = fncLogFile(8, 0)
Else
tmp = fncLogFile(8, 1)
bversand = False
End If
End If
If bversand = False Then
fncKompletterAblauf = False
If fncErrErstell() Then
tmp = fncLogFile(9, 0)
Else
tmp = fncLogFile(9, 1)
End If
Else
fncKompletterAblauf = True
End If
'
End Function
Function fncLogFile(ByVal iFnc As Integer, ByVal iErr As Integer) As Boolean
On Error GoTo errLog
Dim sMeldung As String
Dim slog As String
Dim ilog As Integer
slog = PfadLog & Year(Date) & "_" & Month(Date) & "_Log.txt"
ilog = FreeFile
Open slog For Append As ilog
Select Case iFnc
Case 1
sMeldung = ""
Case 2
sMeldung = "[ " & Date & " - " & Time & " ] - Variablenfuellen ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 3
sMeldung = "[ " & Date & " - " & Time & " ] - Infosholen ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 4
sMeldung = "[ " & Date & " - " & Time & " ] - Open 'Schichtplan.xls' ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 5
sMeldung = "[ " & Date & " - " & Time & " ] - Tabellefuellen ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 6
sMeldung = "[ " & Date & " - " & Time & " ] - Textdatei 'Schichtplan.txt' anlegen ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 7
sMeldung = "[ " & Date & " - " & Time & " ] - Batchdatei 'Mail.bat' anlegen ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 8
sMeldung = "[ " & Date & " - " & Time & " ] - Mailversand starten ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 9
sMeldung = "[ " & Date & " - " & Time & " ] - Fehlermail erstellt und verschickt ... "
If iErr = 0 Then sMeldung = sMeldung & "DONE"
If iErr = 1 Then sMeldung = sMeldung & "ERROR"
Case 10
Dim sErfolg As String
If iErr = 0 Then sErfolg = "erfolgreich"
If iErr = 1 Then sErfolg = "fehlerhaft"
sMeldung = "##########################################" & vbNewLine & _
"Der Schichtplanversand war " & sErfolg & "!" & _
vbNewLine & "##########################################" & vbNewLine
Case 11
sMeldung = "##########################################" & vbNewLine & _
"LOG - " & Date & _
vbNewLine & "##########################################"
End Select
Print #ilog, sMeldung
Close ilog
GoTo skipLog
errLog:
fncLogFile = False
Exit Function
skipLog:
fncLogFile = True
End Function