Lookup a Contact's time zone

Last reviewed on August 15, 2013

DigitalDawn had this question on Outlook Forums:

Is there an Outlook Add-In that can tell you the time or time zone for a contact based on their area code?

I'm not aware of any addins, but it's a great idea. Until then, adding a field to contacts to record the time zone is one option, although you'd need to add the time zone yourself.

You can use a macro to grab the postal code and look up the time zone. While it's not perfect, it is useful for anyone who wants to identify the time zone a person lives in.

I think using the postal code would be better than the phone number's area code, at least here in the US. Thanks to number portability, the person may not be living in the same region the area code is assigned to.

The following two URLs work for US addresses. Any site that includes the zip code in the URL can be used. To use, replace the number with the zip code string. Melissadata's URL accepts the full telephone number or just the area code, if you prefer to use it.

http://www.melissadata.com/lookups/ZipCityPhone.asp?InData=12345&submit=Search
http://www.zip-info.com/cgi-local/zipsrch.exe?tz=tz&zip=12345&Go=Go

At this time, the code opens a web page containing the time zone and other information.

results from melissadata

I'm working on scraping the page and grabbing just the time zone from the page, then displaying it in a message box, writing it to the notes field, or to a custom field.

To use, select a contact and run the macro.

Get the time zone macro


Sub GetContactTimeZone()
   
  Dim strURL As String
  Dim oApp As Object
  Dim strAddress As String
 
  Set oApp = CreateObject("InternetExplorer.Application")
 
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
 Set oContact = ActiveExplorer.Selection.Item(1)
 
strAddress = oContact.MailingAddressPostalCode

ReplaceSpaces strAddress
strURL = "http://www.melissadata.com/lookups/ZipCityPhone.asp?InData=" & strAddress & "=Search"

 
oApp.Navigate (strURL)
oApp.Visible = True
 
'wait for page to load before passing the web URL
Do While oApp.Busy
  DoEvents
Loop
 End If
 
 
Set oApp = Nothing
End Sub
 
 
 
Private Sub ReplaceSpaces(strAddress As String)
  strAddress = Replace(strAddress, " ", "-")
End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

If the Post Coment button disappears, press your Tab key.