I have a Word document that I want to tell me when a certain amount of time has elapsed.
I have a macro (TestLength) to set the length of time I want, and then a separate macro to actually calculate the time and let me know when it's elapsed (StartTest). Since this will be used for timed tests, I only want to enter the length of time once, whereas I will want to calculate the time multiple times with that same length of time. Here is the code I currently have. Everything works fine when I have the TestLenght code and the StartTest code in the same macro, but the way it is now when I run the StartTest macro, it is not recognizing the TimeLength. That makes sense, but I don't know how to tell it to go back and reference the time I put in with the TestLength macro. Any help would be great appreciated!
Public Sub TestLength()
Dim TimeLength As Date
TimeLength = TimeValue(InputBox("Please enter the length of the test in the following format HH:MM:SS.", "Length of Test"))
End Sub
Sub StartTest()
If TimeLength = 0 Then
MsgBox "A time limit for this test has not been entered. Please notify the receptionist immediately.", vbCritical, "Time Missing"
Exit Sub
Else
ActiveDocument.Fields.Update
MsgBox "Read the instructions above and click 'OK' when you are ready to begin.", vbOKOnly, "Begin Test"
Application.OnTime Now + TimeLength, "TimesUp"
Exit Sub
End Sub
Public Sub TimesUp()
MsgBox "Your time is up. The document will now print; please wait for further instructions from the receptionist.", vbOKOnly, "Time is Up"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
I have a macro (TestLength) to set the length of time I want, and then a separate macro to actually calculate the time and let me know when it's elapsed (StartTest). Since this will be used for timed tests, I only want to enter the length of time once, whereas I will want to calculate the time multiple times with that same length of time. Here is the code I currently have. Everything works fine when I have the TestLenght code and the StartTest code in the same macro, but the way it is now when I run the StartTest macro, it is not recognizing the TimeLength. That makes sense, but I don't know how to tell it to go back and reference the time I put in with the TestLength macro. Any help would be great appreciated!
Public Sub TestLength()
Dim TimeLength As Date
TimeLength = TimeValue(InputBox("Please enter the length of the test in the following format HH:MM:SS.", "Length of Test"))
End Sub
Sub StartTest()
If TimeLength = 0 Then
MsgBox "A time limit for this test has not been entered. Please notify the receptionist immediately.", vbCritical, "Time Missing"
Exit Sub
Else
ActiveDocument.Fields.Update
MsgBox "Read the instructions above and click 'OK' when you are ready to begin.", vbOKOnly, "Begin Test"
Application.OnTime Now + TimeLength, "TimesUp"
Exit Sub
End Sub
Public Sub TimesUp()
MsgBox "Your time is up. The document will now print; please wait for further instructions from the receptionist.", vbOKOnly, "Time is Up"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub