Adding Lat/long to polyline from excel

DeepBlue
05-04-2007, 04:52 PM
I have some experience in Excel VBA but am still fairly new. This is the first time I have tried to automate MapPoint with it though. What I want to do is create a Freeform in MapPoint with the 'points' retrieved from the excel workbook.

Lets say that Latitudes were in the A column in Sheet1 and Longitudes were in the B column of Sheet1. I looked up the sample code for polyline and tried playing around with what I need to set the objLoc(x) to, but could not figure out anything that works.

I want to replace the ? with something that will get the latitude and longitude from the excel spreadsheet, and then draw the shape in MapPoint.

************************************************** ****

Sub AddPolylineToMap()

Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLoc(1 To 3) As MapPoint.Location

'Set up the application
Set objMap = objApp.ActiveMap
objApp.Visible = True
objApp.UserControl = True

'Get three locations and zoom in
Set objLoc(1) = ?
Set objLoc(2) = ?
Set objLoc(3) = ?
Set objMap.Location = objLoc(1)

'Create a polyline by connecting these locations
objMap.Shapes.AddPolyline objLoc

End Sub
************************************************** ****
Thanks for the help.

Wilfried
05-05-2007, 02:46 AM
Hi,

You dont tell what exacly is not working. I assume you dont have a polyline. If that is the case I should start to check if the Location objects are correct. You can find this out by putting a pushpin on these locations.

DeepBlue
05-07-2007, 11:35 AM
I have tried a few different things. For example, if I put the latitude and longitude in cells A1:A3 in the form Lat,Long and then try this for the code:

Set objLoc(1) = Worksheets("sheet1").Range("A1")
Set objLoc(2) = Worksheets("sheet1").Range("A2")
Set objLoc(3) = Worksheets("sheet1").Range("A3")

I get a "Run-time error ' 13': Type mismatch" error.

I need to figure out what I need to set the objLoc(X) equal to so that it places the 'points' of the polyline at the locations from the excel spreadsheet.

John Meyer
05-15-2007, 06:59 AM
can you show the format you are using for the lat/long?
Like Wilfried said, try putting pushpins on the map first with code to verify you are passing the lat/long correctly.

 
Web mp2kmag.com
mapforums.com