PDA

View Full Version : Macro to work with different versions of MapPoint



bjvad
08-05-2013, 03:04 PM
Hello,

I developed an excel macro that would read data from an excel file and plot the points in MapPoint. It works fine for me, but when running the macro on someone else's desktop, I get an "ActiveX Component cannot create Object" error at the line of code that is creating an object.

I built the code on my machine that has Microsoft MapPoint 17.0 Object Library (North America) so added that as a reference. When I debug on my clients desktops, they have a different Object Library in their list of references (Microsoft MapPoint 15.0 Object Library, Microsoft MapPoint 18.0 Object Library, etc)

There are many users, so it would be difficult to get them all to install the exact same version I have. Is there a way to create the objects I need by adding my Microsoft MapPoint 17.0 Object Library reference but still run on other clients that have different versions?

I apologize if this is a basic question, I'm sure I'm missing something simple

Here is a snippet of the code



Dim oMap As MapPoint.Application
Dim oLoc As MapPoint.Location
Dim oTerDS As MapPoint.DataSet
Dim oPushPin As Pushpin
Dim oShape As MapPoint.Shape

Application.ScreenUpdating = False
ThisWorkbook.Activate
Set wbMain = ActiveWorkbook
Set oMap = New MapPoint.Application 'Fails here

Winwaed
08-07-2013, 05:40 PM
Usually you want to reference the oldest version that you want to support. Then at install/runtime, Windows/COM will then provide a later version if available.

What you are doing at the moment is asking for something with the 17.0 interface - but the 15.0 machine doesn't have 17.0. However if you asked for 15.0 then it should work on both machines - assuming you don't use any 17.0-specific features.

Eric Frost
08-08-2013, 07:47 AM
Hi bjvad and welcome to the forums!

Another trick is to declare everything as Objects and don't reference anything... this can get around version issues and make the macro more bullet-proof.



Dim oMap As Object 'MapPoint.Application
Dim oLoc As Object 'MapPoint.Location
Dim oTerDS As Object 'MapPoint.DataSet
Dim oPushPin As Object 'Pushpin
Dim oShape As Object 'MapPoint.Shape

Application.ScreenUpdating = False
ThisWorkbook.Activate
Set wbMain = ActiveWorkbook
Set oMap = New MapPoint.Application 'Fails here


However, in doing this you will lose context sensitive help in the Editor, so if you miss that you can replace the declarations as Objects after you are done programming.

bjvad
08-09-2013, 06:05 PM
Thank you very much Eric, that worked!

Eric Frost
08-12-2013, 09:33 AM
Oh great! Glad to help. I just figured out that trick in the last year or so actually. :eek2: