Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Automatically running code
The code works fine, but how and where do you put it for it to start
automatically and run continually. I have it in a Module but I have to manually go in and run it from there. If I put it in Private Sub Workbook_Open() it only shows the current time when opened and does not run continually. Sub clock() If ThisWorkbook.Worksheets(1).Range("C2").Value = "X" Then Exit Sub ThisWorkbook.Worksheets(1).Range("G2").Value = Format(Now, "hh:mm:ss AM/PM") Application.OnTime Now + TimeSerial(0, 0, 60), "clock" End Sub Thanks in Advance! |
#2
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Automatically running code
This slightly modified code will run continuously (up to 1000 hours) and
display the time changing, albeit that there's no way of stopping it other than pressing 'Escape' , that would need to be added to the code. If this is running however, all you'll see is the time changing and the hour glass, you wont be able to do anything in Excel until the code is stopped. IMHO things like this and flashing text etc are best avoided in Excel, Regards, Alan. Sub Clock() If ThisWorkbook.Worksheets(1).Range("C2").Value = "X" Then Exit Sub For i = 1 To 1000 ThisWorkbook.Worksheets(1).Range("G2").Value = Format(Now, "hh:mm:ss AM/PM") Application.OnTime Now + TimeSerial(0, 0, 60), "Clock" Next i End Sub "Richard" wrote in message ... The code works fine, but how and where do you put it for it to start automatically and run continually. I have it in a Module but I have to manually go in and run it from there. If I put it in Private Sub Workbook_Open() it only shows the current time when opened and does not run continually. Sub clock() If ThisWorkbook.Worksheets(1).Range("C2").Value = "X" Then Exit Sub ThisWorkbook.Worksheets(1).Range("G2").Value = Format(Now, "hh:mm:ss AM/PM") Application.OnTime Now + TimeSerial(0, 0, 60), "clock" End Sub Thanks in Advance! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Conform a total to a list of results? | Excel Discussion (Misc queries) | |||
Macro for changing text to Proper Case | Excel Worksheet Functions | |||
Running a Macro automatically from Excel | Excel Worksheet Functions | |||
automatically insert town name after entering zip code | Excel Discussion (Misc queries) | |||
Error trapped only while stepping through the code - Not triggered when run | Excel Discussion (Misc queries) |