Microsoft Office Tutorials and References
In Depth Information
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.
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
Open a new workbook.
From your worksheet, press Alt+F11 to go to the Visual Basic Editor.
From the menu bar in the VBE, click Insert ➪ Module.
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:
Open a With structure for the destination worksheet:
Declare a String type variable for the website address:
Dim strURL As String
Define the website address from which the information will be imported to your worksheet:
strURL = _
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
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: