Automating MapPoint with Excel
VBA - Tutorial 7
This tutorial shows how to create
Drawing Labels on the map based on a list of data in Excel. Earlier
tutorials can be found here
1,
2,
3,
4,
5,
and
6.
In this tutorial a list of counties in Arkansas and labeled with some
sample data. The list of counties in the Excel spreadsheet along with
the code can be downloaded
here.
After you have downloaded and unzipped the spreadsheet, to Run the
macro go to Tools | Macro | Macros and run LabelMap. The macro will
open a new MapPoint map and display the labels. The resulting map can
be downloaded
here
(MapPoint 2010 PTM file) or click on the thumbnail to the right to view
the full map screenshot.
This first line declares the MapPoint Application object outside of the
Subroutine. This allows MapPoint to stay open after the program has
ended.
Dim
MPAPP As MapPoint.Application
Public Sub LabelMap()
These next few lines instantiate MapPoint and
defines the Map object.
Set MPAPP = CreateObject("MapPoint.Application")
MPAPP.Visible = True
Dim objMap As MapPoint.Map
Set objMap = MPAPP.ActiveMap
The next several line declare the variables
used by the program.
Dim row As Integer
Dim state, county, szLabel As String
Dim fLabel As Double
Dim objLocation As MapPoint.Location
Dim objPushpin As MapPoint.Pushpin
Dim objFindResults As MapPoint.FindResults
Dim objShape As MapPoint.Shape
row = 2
The main portion of the code is all within a loop that
works down through the list of locations (in this case counties) until
it reaches a blank line.
Do While Cells(row, 1) <> ""
state = Cells(row, 1)
county = Cells(row, 2)
fLabel = Cells(row, 3)
szLabel = Int(fLabel)
The next two lines find the country and gets a
Location object at which to draw the label.
Set objFindResults =
objMap.FindPlaceResults(county & ", " & state)
Set objLocation = objFindResults(1)
Draw the label and set the text and border
weight.
Set objShape =
objMap.Shapes.AddTextbox(objLocation, 30, 30)
objShape.Text = szLabel
objShape.Line.Weight = 1
row = row + 1
Loop
End Sub
Everyone loves a good mapping utility! Hopefully some of you will find
this script useful.
If you have any questions,
suggestions, or enhancements you would like to share please post in the
MapPoint
/ Excel VBA discussion thread.
Keep an eye out for
a continuation of this series in
future issues.
MapPoint 2010 API Changes
The MapPoint Object Model has been updated
significantly - the most since at least the 2002 version of MapPoint.
Methods
The new methods for Microsoft MapPoint 2010 are:
-
ImportGPX
(Application and MappointControl
objects)
-
ExportGPX
(Application and MappointControl
objects)
-
Reverse
(Route object)
-
UpdateConstruction
(Route object)
-
ZoomTo
(Route object)
-
BasicRenderingOnly
(Map object)
-
DefaultRendering
(Map object)
-
ShowInOnlineMap
(Map object)
-
SendToMobile
(Map object)
-
ExportToExcel
(SelectedArea object)
Objects
The topics in this section give details about
objects and collections by providing a graphic of the element's object
model inheritance and an explanation of the object or collection. Also
provided is a list of associated methods, properties, and events as
applicable.
The new objects for Microsoft MapPoint 2010 are:
-
MapFeatures
collection
-
MapFeature
object
-
GPSNavigation
object
Properties
The new properties for Microsoft MapPoint 2010 are:
-
ShowNavigation
(Application and MapPointControl
objects)
-
LargeToolbarButtons
(Toolbars collection)
-
MapFeatures
(Map object)
-
GPSNavigation
(Map object)
-
PushpinsVisible
(DataSet object)
-
Application
(MapFeatures
collection, MapFeature
and GPSNavigation objects)
-
Parent
(MapFeature and GPSNavigation
objects)
-
Name
(MapFeature object)
-
Index
(MapFeature object)
-
DetailLevel
(MapFeature object)
-
Navigation
(GPSNavigation object)
-
FullScreenNavigation
(GPSNavigation object)
See the Help File for more details.
MapPoint
Consultants and Products Directories
Find developers and experienced MapPoint
consultants who can help you with your next project or program costum
solutions helping to integrate MapPoint with your business
processes.
If you are a
consultant who know MapPoint or Bing Maps, this is a terrific way
to read our audience and share information about your capabilities,
services, describe past projects, and communicate your availability.
You are welcome to post your resume and keep your thread or profile
updated periodically with references, new offerings, and contant
information. Get started today by posting "New Thread" in the
MapPoint
Consultant Directory. Listings are free, but there is also an
opportunity to
become
a sponsor for a more prominent listing and a link from the
home page.
Similarly, about six months ago, we also started a new
Products
Directory
for MapPoint Add-ins, Bing Maps tools, and related products. If you
have a MapPoint/Bing Maps Add-in or tool, list it in here to get some
great
visibility and exposure for your product. To keep your product near the
front of the directory, you can post periodically updates, tutorials,
case studies, or other new information about your product.
MP2K
Magazine Twitter Channel
Interesting news items and updates for
MapElves, MapForums, and MP2K Magazine are posted to our twitter
channel at
http://twitter.com/mp2kmag.
Here's the
original
announcement on MapForums regarding the launch of our twitter
channel.
Get
Published in MP2K
Magazine
If you have a MapPoint presentation, neat programming technique, or
would simply like to share the ways in which you are using MapPoint
technology or any other ideas, contact us to discuss how we can turn
your knowledge into
an article and share your experience with the rest of the MapPoint
community of users and developers.
Thanks to
Marvin
Hlavac for allowing us to use the
picture on the right of his Maltese puppy eating from the MapPoint
mug.