Word VBA Help

ApesMM273

New Member
Joined
Dec 9, 2003
Messages
40
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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,225,482
Messages
6,185,262
Members
453,283
Latest member
Shortm88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top