How to Quickly Get the ZIP Code for the Address of an Outlook Contact

At times, you only know a contact’s address without the address’s ZIP code. In this case, you may want to get the ZIP code for the address in your Outlook. This post will introduce a method to quickly get the ZIP code for a contact’s address.

Many users hope that Outlook can provide an inbuilt function supporting them to rapidly get the ZIP code for a contact’s address. Although Outlook doesn’t have such a feature, it still can be realized with a bit of scripting. Thereinafter, we will take U.S. address as an example to teach you how to get it.

Quickly Get the ZIP Code for the Address of an Outlook Contact

Get the ZIP Code for the Address of a Contact

  1. At the very outset, launch your Outlook program.
  2. Then, access VBA editor with reference to the previous article – “How to Run VBA Code in Your Outlook“.
  3. Next, copy and paste the following VBA code into a project or module.
Sub GetZIPCodeforUSAddress()
    Dim objContact As Outlook.ContactItem
    Dim strStreet, strAddress1, strAddress2, strCity, strState As String
    Dim strURL As String
    Dim strFoundInfo As String
    Dim Addr As String
    Dim Zip As String
    Dim i As Integer
    Dim objInternetExplorer As Object
    Dim strZIPCode As String
    Dim strMsg As String
 
    'Get the source contact
    Set objContact = Application.ActiveExplorer.Selection(1)
 
    'Get the contact business address
    'You can change to Home or Other address as per your needs
    strStreet = objContact.BusinessAddressStreet
    strCity = objContact.BusinessAddressCity
    strState = objContact.BusinessAddressState
 
    strAddress1 = Left(strStreet, InStr(strStreet, ","))
    strAddress1 = Replace(Trim(strAddress1), " ", "+")
    strAddress2 = Right(strStreet, Len(strStreet) - InStr(strStreet, ","))
    strAddress2 = Replace(Trim(strAddress2), " ", "+")
 
    'Look up ZIP Code via "usps.com"
    strURL = "https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=0&companyName=&address1="
    strURL = strURL & strAddress1 & "&address2=" & strAddress2 & "&city=" & strCity & "&state=" & strState & "&urbanCode=&postalCode=&zip="
 
    Set objInternetExplorer = CreateObject("InternetExplorer.Application")
    objInternetExplorer.navigate strURL
 
    Do Until (objInternetExplorer.readyState = 4) And Not (objInternetExplorer.Busy)
       DoEvents
    Loop
 
    'Extract the ZIP Code for the website
    strFoundInfo = objInternetExplorer.Document.Body.innerText
    strFoundInfo = Right(strFoundInfo, Len(strFoundInfo) - 2400)
    If InStr(1, strFoundInfo, "Unfortunately, this address wasn't found") > 0 Then
       strZIPCode = ""
    Else
       strFoundInfo = Mid(strFoundInfo, InStr(1, strFoundInfo, "Here's the full address") + 94, 100)
       strZIPCode = Mid(strFoundInfo, InStr(1, strFoundInfo, "-") - 5, 10)
    End If
 
    'Promp you of the ZIP Code
    If strZIPCode <> "" Then
       strMsg = "Name: " & objContact.FullName & vbCr & "ZIP Code: " & strZIPCode & vbCr & vbCr & "Do you want to add to Contact now?"
 
       If MsgBox(strMsg, vbYesNo + vbQuestion) = vbYes Then
          With objContact
              .BusinessAddressPostalCode = strZIPCode
              .Save
          End With
       End If
    Else
       MsgBox "Not Found"
    End If
End Sub

VBA Code - Get the ZIP Code for the Address of a Contact

  1. Subsequently, close the current window.
  2. After that, add this macro to Quick Access Toolbar.
  3. Finally, you can have a shot by the following steps.
  • Firstly, select a contact whose address you want to get ZIP code for.
  • Later, click the macro button in the Quick Access Toolbar.Run Macro on Selected Contact
  • After a while, you will get a message like the followings screenshot:Message Prompting ZIP Code
  • If you select “Yes”, the ZIP code will be added to the contact at once.Added ZIP Code

Resolve Outlook Problems

As we all know, no program can be immune from error and corruption. The same holds true for Outlook application. Thereby, you will encounter various problems in your Outlook. In order to protect your Outlook data, you need to resolve issues as soon as you encounter them. At this point, you can use the inbox repair tool in the first place. If it fails, you ought to take aid of a more potent external tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted sql and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *