+ Reply to Thread
Results 1 to 5 of 5

VBA interface with MapPoint (datatypes)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    VBA interface with MapPoint (datatypes)

    What I'm trying to do is have Excel interface with MapPoint (v17 - 2010) in order to automatically work out drive times between two grid references. However, while the code below works perfectly if I have 2 postcodes, if I try it with grid refs instead it gives me the error: "The requested member of the collection does not exist. Use a valid name or index number".

    
        Dim objApp As New MapPoint.Application
        Dim objMap As MapPoint.Map
        Dim objRoute As MapPoint.Route
       
        Set objMap = objApp.NewMap
        Set objRoute = objMap.ActiveRoute
        objApp.Visible = True
        objApp.UserControl = True
        
    
        szZip1 = Range("e5").Value
        szZip2 = Range("I5").Value
        
    
      '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
        objMap.Saved = True
      Range("L1").Value = CStr(objRoute.DrivingTime / geoOneMinute)


    The problem is I only have one postcode, the second data source is worked out from looking up the northing and easting (grid ref) of a number of postcodes from a database I have (yep, of 1.7 million postcodes and their grid refs) and taking the average.....but I have no way to convert back the other way.

    So.....I either need someone to tell me how I can get the above code working with grid refs instead of postcodes or a way to get the nearest postcode from a grid ref. Any ideas?

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: VBA interface with MapPoint (datatypes)

    Came up with a plan to reverse look up grid refs against the nearest valid postcode......but I'll leave the thread up in case anyone does know anything about interfacing with MapPoint cos any info would be handy.

  3. #3
    Registered User
    Join Date
    01-25-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VBA interface with MapPoint (datatypes)

    What version of MapPoint do you have? They did add the ability to look up OS Grid Reference, but I forget in which version they first added it. Maybe MapPoint 2006 or 2009.

    Here's an example of how to use it.

    Sub ZoomToLocation()
    
      'Zooms to a spot near Washington, England.
      Dim objApp As New MapPoint.Application
      Dim objMap As MapPoint.Location
    
      'Get the location of a spot in the U.K. using OS Grid reference.
      Set objLoc = objApp.ActiveMap.LocationFromOSGridReference( _
        "TQ12321232", 100)
      objLoc.GoTo
    
    End Sub
    Do you need help with modifying your code to make use of this?

    Eric
    Last edited by Eric Frost; 01-25-2013 at 11:22 AM.
    Map Forums - http://www.MapForums.com

  4. #4
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: VBA interface with MapPoint (datatypes)

    Hugely helpful, thanks Eric.

  5. #5
    Registered User
    Join Date
    01-25-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VBA interface with MapPoint (datatypes)

    Great! Glad to be of help. We have published a lot more Excel & MapPoint example code http://www.mp2kmag.com/update

    Eric

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1