J.E.
Here is the code
The message boxes are in Dutch. I hope that is not a problem
Many Thanks in advance
Public RunWhen As Double
Public Const cRunIntervalSeconds = 15 ' two minutes
Public Const cRunWhat = "The_Sub"
Public x
Public y
Sub StartTimer1()
'StartTimer1 start vanaf 05:00 uur
MsgBox "Timer1 gestart"
RunWhen = TimeSerial(5, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:="StartTimer2",
schedule:=True
End Sub
Sub StartTimer2()
'StartTimer2 start als StartTimer1 om 05:00 uur geactiveerd is geworden
'De Timer functie wordt overgegeven aan Timer2
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:="PrintenOpTijd",
schedule:=True
End Sub
Sub PrintenOpTijd()
If Format(Now, "hh:mm") > "05:00" And Format(Now, "hh:mm") < "05:02" Then
Response = MsgBox("Zijn alle gegevens ingevuld?" & Chr(13) & Chr(13) & _
"* Druk YES indien alle gegevens zijn ingevuld." & Chr(13) & _
" De dagstaat wordt afgedrukt en de datum wordt aangepast" &
Chr(13) & Chr(13) & _
"* Druk NO indien nog gegevens moeten worden toegevoegd" & Chr(13) &
_
" Achter 10 min ben ik terug", vbYesNo)
If Response = vbYes Then
Printen
StopTimer2
Exit Sub
End If
ElseIf Format(Now, "hh:mm") > "05:02" Then
StopTimer2
Exit Sub
End If
StartTimer2
End Sub
Sub StopTimer2()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedure:="StartTimer2",
schedule:=False
MsgBox "Timer2 is gestopt"
End Sub
Sub StopTimer1()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedure:="StartTimer1",
schedule:=False
MsgBox "Timer1 is gestopt"
End Sub
Sub Printen()
If Time > #5:00:00 AM# And Time < #8:00:00 AM# Then
Response = MsgBox("Na het printen wordt de datum aangepast" & Chr(13) &
_
"aan een nieuwe dag [momentele datum]" & Chr(13) & _
"Weet je zeker dat je verder wilt", vbYesNo + vbCritical, "Printen
Dagstaat")
If Response = vbYes Then
AantalSheets = Worksheets.Count
For pSheetNummer = 1 To AantalSheets
Worksheets(pSheetNummer).Select
If ActiveSheet.Name = "KALD Ber" Then
pDIR = "Hydin\"
pZoom = 90
pActiveSheet = "KALD Ber"
pCelDatum = "V1"
End If
If ActiveSheet.Name = "KALD Zuiv" Then
pDIR = "Zuivering\"
pZoom = 100
pActiveSheet = "KALD Zuiv"
pCelDatum = "Q1"
End If
WriteDagstaatKALD 'Bewaar eerst de
huidige gegevens
With ActiveSheet.PageSetup 'Print de sheet 2 maal
.Zoom = pZoom
End With
' ActiveWindow.SelectedSheets.PrintOut Copies:=2,
Collate:=True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=True,
Collate:=True
MsgBox "Printen"
ActiveSheet.Unprotect password:="p"
Set vs = Workbooks("Kald.xls").Sheets(pActiveSheet)
Range(pCelDatum) = Now
ActiveSheet.Protect password:="p"
Next pSheetNummer
Else
If Response = vbNo Then Exit Sub
End If
Else
MsgBox "Er kan alleen geprint worden tussen 05:00 en 08:00 uur"
End If
End Sub