Thanks to all of you out there who post and let newbies like me discover code to automate Mappoint. The first macro below create a mappoint map with a number of pushpins on it from Excel and it works fine. The problem I fine is everytime I run the macro a new mappoint map is opened and after a while I've got a lot of maps opened. I searched web and forum looking for code to close mappoint each time I run the macro ( see sub routine to close Mappoint) which works fine if Mappoint is open, however if its not I get a error message ActiveX component can't create object. Any ideas as to what's happening and how to fix it.
Private Sub submitMapChoice_Click2()
Dim objMap As MapPoint.Map
Dim objLoc As MapPoint.Location
Dim objPushpin As MapPoint.Pushpin
' sub routine to close Mappoint
Set oApp = GetObject(, "MapPoint.Application")
oApp.ActiveMap.Saved = True
oApp.Quit
Set oPApp = Nothing
Set oApp = CreateObject("MapPoint.Application.NA")
Set objMap = oApp.NewMap
nReadRow = 2
Do While Sheets("MapData").Cells(nReadRow, 1) <> ""
MyLat = Sheets("MapData").Cells(nReadRow, 1)
MyLon = Sheets("MapData").Cells(nReadRow, 2)
szname = Sheets("MapData").Cells(nReadRow, 4)
Set objLoc = objMap.GetLocation(MyLat, MyLon, 0)
Set objPushpin = objMap.AddPushpin(objLoc, szname)
objPushpin.Note = Sheets("MapData").Cells(nReadRow, 4)
objPushpin.BalloonState = geoDisplayName
nReadRow = nReadRow + 1
Loop
oApp.Visible = True
oApp.WindowState = geoWindowStateMaximize
objMap.DataSets.ZoomTo
objMap.DataSets(1).Name = "MarketPointe - LandTracker"
End Sub