ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro help in capturing server time (https://www.excelbanter.com/excel-programming/310121-macro-help-capturing-server-time.html)

saurabhb

Macro help in capturing server time
 
Hi

Need help with this VB code.

What the current code does is - Picks up time from US Navy websit
http://tycho.usno.navy.mil

I would like to modify it to capture the server time (The time I get b
running the command "net time" at the command prompt in Windows).

For reference the IP address of the server can be taken to b
192.168.1.17

Thanks,
Saurabh


Sub TimeAfterTime()

With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With

Dim WebCopy As Object
Dim WebURL As String
Set WebCopy = Sheets("Sheet2")
WebURL = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"
WebCopy.Activate
Cells.Clear

With WebCopy.QueryTables.Add(Connection:="URL;" & WebURL
Destination:=WebCopy.Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Range("1:2").EntireRow.Delete
Range(("A2"), Range("A2").End(xlDown)).EntireRow.Delete
With Range("A1")
.Replace What:="
", Replacement:=""
.Replace What:="UTC", Replacement:=""
.Replace What:=".", Replacement:=""
.Replace What:=", ", Replacement:=", " & Year(Now) & " "
.Value = Trim(.Value)
.NumberFormat = "mmmm d, yyyy, hh:mm:ss"
End With

Range("B1").FormulaR1C1 = "=R1C1-TIME(5,,)"
Range("B1").Value = Range("B1").Value
Columns(2).AutoFit
Columns(1).Delete Shift:=xlToLeft

With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With

End Su

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com