Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Richard
 
Posts: n/a
Default Automatically starting code

The code works fine, but how and where do you put it for it to start
automatically. I have it in a Module but I have to manually go in and run it
from there.
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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB
 
Posts: n/a
Default Automatically starting code

You could put it in the ThisWorkBook module, and declare it as an event
handler, such as:

Private Sub Workbook_Open()
'your code here
End Sub

This example would run whenever the workbook is opened. If you click on the
drop down boxes in the ThisWorkBook module you'll see there are a variety of
events to which you could attach your code.

"Richard" wrote:

The code works fine, but how and where do you put it for it to start
automatically. I have it in a Module but I have to manually go in and run it
from there.
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!

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Richard
 
Posts: n/a
Default Automatically starting code

Clock will change to current time but will not run continually if I put it in
Private Sub Workbook_Open()


"JMB" wrote:

You could put it in the ThisWorkBook module, and declare it as an event
handler, such as:

Private Sub Workbook_Open()
'your code here
End Sub

This example would run whenever the workbook is opened. If you click on the
drop down boxes in the ThisWorkBook module you'll see there are a variety of
events to which you could attach your code.

"Richard" wrote:

The code works fine, but how and where do you put it for it to start
automatically. I have it in a Module but I have to manually go in and run it
from there.
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!

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB
 
Posts: n/a
Default Automatically starting code

I think all you need to do is call your sub from the event handler. It looks
like your sub uses OnTime to call itself to do the updating.

Private Sub Workbook_Open()
Call Clock
End Sub


"Richard" wrote:

Clock will change to current time but will not run continually if I put it in
Private Sub Workbook_Open()


"JMB" wrote:

You could put it in the ThisWorkBook module, and declare it as an event
handler, such as:

Private Sub Workbook_Open()
'your code here
End Sub

This example would run whenever the workbook is opened. If you click on the
drop down boxes in the ThisWorkBook module you'll see there are a variety of
events to which you could attach your code.

"Richard" wrote:

The code works fine, but how and where do you put it for it to start
automatically. I have it in a Module but I have to manually go in and run it
from there.
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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
automatically insert town name after entering zip code accessnovice Excel Discussion (Misc queries) 2 July 12th 05 10:01 PM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 4th 05 10:50 AM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 3rd 05 03:40 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM


All times are GMT +1. The time now is 04:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"