Microsoft Office Tutorials and References
In Depth Information
Try It
Try iT
What is today’s date, and what is the current time of day? In this lesson you create a Web query to
import a display of the current day and time for several North American time zones.
lesson requirements
For this lesson, you access the website to the United States Naval Observatory, where the day and
time are recorded on the Master Clock of the United States Navy. To get the sample database files
you can download Lesson 23 from the book’s website at www.wrox.com .
step-by-step
1.
Open a new workbook.
2.
From your worksheet, press Alt+F11 to go to the Visual Basic Editor.
3.
From the menu bar in the VBE, click Insert Module.
4.
In your new module, type Sub TimeAfterTime and press the Enter key. VBA will produce the
following two lines of code, separated by an empty line:
Sub TimeAfterTime()
End Sub
5.
Open a With structure for the destination worksheet:
With Worksheets(“Sheet1”)
6.
Declare a String type variable for the website address:
Dim strURL As String
7.
Define the website address from which the information will be imported to your worksheet:
strURL = _
“http://tycho.usno.navy.mil/cgi-bin/timer.pl”
8.
For consistency, I prefer to activate the worksheet that will receive the web data. Cell A1 is a
convenient cell to start with:
Application.Goto .Range(“A1”), True
9.
Clear the cells in the worksheet so you know the data being imported will not be confused
with other data you may have imported previously and not yet deleted:
Cells.Clear
Search JabSto ::




Custom Search