J
Jase
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
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