View Full Version : Close Maps from VB
04-06-2009, 09:27 AM
I want to run a code from an Excel workbook that will close all Mappoint 2004 Euroupe Maps that are open without saving them.
I have found code on MDSN but couldnt get it to work.
Please can you help ?
04-06-2009, 11:29 AM
You will need to find a reference to each and every Application object.
Then you will need to set each app's ActiveMap.Saved property to 'true' before closing each app. Do you have the code? What were the error(s)?
04-06-2009, 01:11 PM
Hi Richard , thanks for the response.
This is all a bit new to me, so sorry if i dont make sense.
The code below is activated from an Xl workbook but before launching a new Map i require the script to close any Maps that are already open.
Please could you advise on what code lines i need to add ?
Dim objApp As New MapPoint.Application
Dim szconn As String
Dim oDS As MapPoint.DataSet
Dim objLoc As MapPoint.Location
l = Sheets("Maintanance Sector Cover").Range("A1").End(xlDown).Row
objApp.Visible = True
objApp.UserControl = True
szconn = ActiveWorkbook.FullName & "!Map!A1:B" & l
Set oDS = .LinkTerritories(szconn, "Postcode Sector", geoCountryeurope, , geoImportExcelA1)
04-06-2009, 01:19 PM
I don't see why you need to make sure any existing MapPoint's are closed?
04-06-2009, 01:45 PM
Its a bit confussing but here goes....
Our Field mangers will be sent a spreadsheet that contains Postcode Secotors in column A and their engineers names in Column B.
They will create a Map by activating the above code, and then they will make adjustments to the spreadsheet that will update the map i.e change B21 1 from Dave to Paul.
However, after they initally create the linked Map they will click the create territory button so the the Postocde Sectors are shown on the Map, but this then breaks the link, which is a problem.
So my idea was just to create a new map after they have made their adjustments but to make sure our managers are looking at the latest map i'll close the others down first.
Is there a better way around this ?
04-06-2009, 03:45 PM
You use use the Data Import instead of the Data Link? Then there would be no link to break.
Also you should be able to keep a valid reference to the map application inside your Excel VBA code? Ie. you would just use the same MapPoint instance.
04-07-2009, 04:00 AM
The Link is required because the managers will be making adjustments to the spreadsheet and then flicking to the Map to see the alterations Mapped.
Then once they are happy with their alterations they'll save the Map and spreadsheet and return to myself.
08-28-2009, 04:35 PM
Just to clarify, there's another thread called "Close the map" that describes what happens when you use a line of code like this:
objMapPointApp.ActiveMap.Saved = True
objMapPointApp is my MapPoint application object and ActiveMap refers to whichever map is open in it. If you add .Saved = True, it makes MapPoint think the map has been saved so it doesn't prompt you to save. The map isn't, in fact, saved; setting the saved property to true does not actually save it. Then say
to close MapPoint.
So for each MapPoint application object, you just have to use the above two lines to close the map without saving.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO