#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 117
Default REAL TIME CLOCK

I am trying to display an actual time clock on a worksheet with the following
code....

Function GetRealDate() As Date

Dim ieApp As Object
Dim i As Long
Dim strTime As String
Dim strHour As String
Dim strMinute As String
Dim strSecond As String
Dim lFirstCom As Long

Const sURL = "http://www.time.gov/timezone.cgi?Central/d/-6"
Const lElement As Long = 36
Const ieREADYSTATE_COMPLETE As Long = 4

Set ieApp = CreateObject("InternetExplorer.Application")

ieApp.navigate sURL

Do
DoEvents
Loop Until ieApp.ReadyState = ieREADYSTATE_COMPLETE

strTime = Left(ieApp.Document.all(lElement).innertext, 40)

'store hour
strHour = Left(strTime, 2)

If Right(strHour, 1) = ":" Then
strHour = Left(strTime, 1)
End If

'store minute
strMinute = Mid(strTime, 4, 2)
'store second
'strSecond = Mid(strTime, 7, 2)

Range("I2").Value = strHour
Range("J2").Value = strMinute
'Range("C1").Value = strSecond

End Function

Then i paste this onto the sheet that i want to run the clock and i get an
error 1004
Option Explicit
Sub Test()

While 1 = 1
GetRealDate
Wend

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default REAL TIME CLOCK

Works for me when I copy and paste everything into a general module in a
workbook.

What do you mean by "Then I paste this onto the sheet that i want to run the
clock"?

Paste the macro into a general module.


Gord Dibben MS Excel MVP

On Fri, 7 Mar 2008 11:23:02 -0800, Jase wrote:

I am trying to display an actual time clock on a worksheet with the following
code....

Function GetRealDate() As Date

Dim ieApp As Object
Dim i As Long
Dim strTime As String
Dim strHour As String
Dim strMinute As String
Dim strSecond As String
Dim lFirstCom As Long

Const sURL = "http://www.time.gov/timezone.cgi?Central/d/-6"
Const lElement As Long = 36
Const ieREADYSTATE_COMPLETE As Long = 4

Set ieApp = CreateObject("InternetExplorer.Application")

ieApp.navigate sURL

Do
DoEvents
Loop Until ieApp.ReadyState = ieREADYSTATE_COMPLETE

strTime = Left(ieApp.Document.all(lElement).innertext, 40)

'store hour
strHour = Left(strTime, 2)

If Right(strHour, 1) = ":" Then
strHour = Left(strTime, 1)
End If

'store minute
strMinute = Mid(strTime, 4, 2)
'store second
'strSecond = Mid(strTime, 7, 2)

Range("I2").Value = strHour
Range("J2").Value = strMinute
'Range("C1").Value = strSecond

End Function

Then i paste this onto the sheet that i want to run the clock and i get an
error 1004
Option Explicit
Sub Test()

While 1 = 1
GetRealDate
Wend

End Sub


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
How do I calculate time in excel (clock in and clock out chad Excel Discussion (Misc queries) 3 January 7th 08 10:09 PM
Real-time clock in excel Daoud Fakhry Excel Discussion (Misc queries) 8 August 12th 07 09:26 AM
how do i insert a real time clock in excel ? daredevilzx9 Excel Discussion (Misc queries) 3 June 27th 07 12:31 PM
Change EXCEL Clock to Standard Clock or Military Time YoMarie Excel Worksheet Functions 4 April 29th 07 08:39 PM
can cell's act like time clock at a certen time/date for payments Colin2u Excel Discussion (Misc queries) 6 August 5th 05 12:20 AM


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

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

About Us

"It's about Microsoft Excel"