Option
Explicit
Private
Sub
Workbook_Open()
Application.Calculation = xlCalculationAutomatic
UnSaved =
True
End
Sub
Private
Sub
Workbook_BeforeClose(Cancel
As
Boolean
)
If
UnSaved
Then
MsgBox (
"Bitte erst speichern"
)
End
If
If
UnSaved
Then
Cancel =
True
End
Sub
Private
Sub
Workbook_BeforeSave(
ByVal
SaveAsUI
As
Boolean
, Cancel
As
Boolean
)
Dim
Msg1, Style1, Title1, Icon1, kein_workcenter, Msg2, Style2, Title2, Icon2, Datum_in_Zukunft
Dim
Zeile
As
Long
Dim
Heute
Dim
tbl
As
ListObject
Set
tbl = Tabelle2.ListObjects(1)
Style1 = vbExclamation
Title1 =
"Kein Workcenter angegeben"
Msg2 =
"Datum liegt in der Zukunft. Ist das korrekt?"
Style2 = vbQuestion + vbYesNo
Title2 =
"Richtiges Datum?"
Heute =
Date
For
Zeile = 1
To
tbl.ListRows.Count
If
tbl.DataBodyRange(Zeile, 2) <>
""
Then
If
tbl.DataBodyRange(Zeile, 4) =
""
Then
kein_workcenter = MsgBox(
"In Zeile "
& Zeile + 3 &
" wurde kein Workcenter angegeben. Achtung Datei wurde nicht gespeichert"
, Style1, Title1)
Cancel =
True
: UnSaved =
True
Exit
Sub
End
If
End
If
Next
Zeile
If
(Tabelle2.Range(
"B1"
).Value) > Heute
Then
Datum_in_Zukunft = MsgBox(Msg2, Style2, Title2)
If
Datum_in_Zukunft = vbNo
Then
DatumSchicht.Show
Cancel =
True
: UnSaved =
True
Exit
Sub
End
If
End
If
x = 0
Sheets(
"Übersicht JobCard"
).
Select
Sheets(
"Übersicht JobCard"
).Protect
Sheets(
"JobCard erstellen"
).Protect
UnSaved =
False
End
Sub