Driving Distance Between 2 Zip Codes.
I'm trying to create a macro in Excel to import the
driving distance between 2 zip codes from MapPoint 2006. Any suggestions?
Eric Frost
04-12-2007, 05:01 PM
Check out this thread and example code, it should be enough to get you started.
Also, see the example code at Working With Excel and MapPoint - MP2K Magazine (http://www.mp2kmag.com/excel)
Eric
Eric,
Thank you so much! I finally got it working & it's working great.
I had to make some minor modifications. This is the exact code I used:
Dim oApp As MapPoint.Application
Private Sub CalculateDrivingDistance()
Set oApp = CreateObject("MapPoint.Application.NA.13")
oApp.Visible = True
Set objMap = oApp.NewMap
Set objRoute = objMap.ActiveRoute
szZip1 = Worksheets("Sheet1").Cells(2, 1)
szZip2 = Worksheets("Sheet1").Cells(2, 2) 'Add route stops and calculate the route
objRoute.Waypoints.Add objMap.FindResults(szZip1).Item(1)
objRoute.Waypoints.Add objMap.FindResults(szZip2).Item(1)
objRoute.Calculate Worksheets("Sheet1").Cells(2, 3) = objRoute.Distance
End Sub
----------------------------------------------------------------------
Now I'm trying to tweek it some more.
How would I add in the driving time
& how could I make MapPoint go to the back automatically so I only see the Excel spread sheet?
Thanks Again!
Sincerely,
Art
Eric Frost
04-18-2007, 12:00 PM
Just comment out this line or change it to false!
oApp.Visible = True