MapWinGIS control in MS Word document

Are there sample MS Word documents somewhere that I can download to see examples of embedding a MapWinGIS control in a MS Word document to allow a user to interact with it. For example, a map with multiple layers (e.g., shapefile, georeferenced raster)? I’d like to get a feel for how well a MapWinGIS ActiveX control works in a .docx or .docm file before jumping into doing any development with them.

Hello @dpmcmlxxvi

I don’t know of any sample code to embed the map into a Word Document. I’ve seen (and tried myself) adding the map to a Form in an Access database, and it is programmable using VBA code. It may be that you can build a simple Access app that provides the functionality you’re looking for, and add a link to the Access app in your Word document.

Looking just now, I did not see a way to add any COM object to a Word document. However, I found this Security update from Microsoft:

https://support.microsoft.com/en-us/help/4058123/security-settings-for-com-objects-in-office

in which it looks like Microsoft specifically disables embedding COM objects in Office documents, for security reasons. You may need to look into this.

The short of it is that if you know how to embed any COM object into an Office document, the principal would be the same for the MapWinGIS component.

I hope that helps.

Regards.
Jerry.

@jerryfaust Thanks. I was able to add a map control to a Word document. After installing MapWinGIS I could manually insert the control through Word’s ribbon controls and also programmatically using the C# .NET API. The link you provided about Office COM objects being disabled doesn’t appear to be the case on my machine. Perhaps that registry setting is used by enterprise admins.

However, while I can add a shapefile vector layer, the map tiles do not display. I have tried all of the providers, including OSM, but none get displayed. Do you have any suggestions on what is the best way to diagnose the problem?

Thanks

Hello @dpmcmlxxvi

Both the Tiles class and the TileProvider class have methods like:

get_ErrorMessage(LastErrorCode)

You can try that after attempting to load the tiles.

Another option would be to set up a Global Callback, which would hopefully return errors or status as they occur.

Also have a look at https://www.mapwindow.org/documentation/mapwingis4.9/getting_started.html
You need to set the Tiles provider, the projection and the known extents.
If your shapefile has a proper .prj file the last options are optional.

I almost exclusively use MapWinGIS with Excel, here we had a bit of a problem with tiles too - it turned out that we have a proxy server for the internet and that was messing things up - I now get users to enter their username and password, look at Tiles.SetProxyAuthentication if you think you’re in the same situation.

@jerryfaust @PipzUK @pmeems Curious, when I try to use any functionality from the Tiles class in a VBA script in MS Word I get an “automation error”. Specifically, the error is

Run-time error '-2147319779 (8002801d)':
Automation error
Library not registered. 

I’m not a VBA expert but the error suggests the library was not installed or registered properly. However, the installation seemed to run fine and the map seems to otherwise work (e.g., I am able to add layers, like a shapefile or raster image just fine).

FYI, I installed MapWinGIS-only-v5.0.1.0-x64 and am using Word v16.0. The 32-bit version didn’t work.

Hello @dpmcmlxxvi

I have seen this, but have not yet figured it out. I believe that it is machine/setup specific.

I first saw this when I sent a program to a customer. The program worked on my development machine, but on their machine they got the “Library not registered” error, even though the OCX was registered on their system. And as with you, some calls were working, but others were not.

I was able to reproduce the problem on another system, but could not debug it since the development tools were not there. I tried to verify other dependencies, such as the msvc runtime, but could not resolve it at the time. The error at that time was with the Map.Extents property, which at that time was declared as IDispatch instead of IExtents. I thought that might be related to the problem, but we have since changed that definition.

Yesterday, I created a Word document with an embedded map. I did not get the automation error, but the OSM tiles WERE NOT visible (although it’s logo was displayed in the lower corner). I copied that same document to another development machine, and on this one, the OSM tiles ARE displayed.

So at least at this point, I believe that it is somehow machine/configuration/setup? dependent, but I just don’t know what it is. I will try to debug on the dev machine that does not display the tiles to see if I get any clues. Hopefully we’ll get this figured out.

Regards,
Jerry.

EDIT: One further note, the development machines on which I do not get the error are machines on which I build the OCX, as opposed to just installing the OCX. This is likely a clue.

Interesting, VERY interesting, I’ve just started experiencing this error with the tiles class on my machine at work. We’re poised to update to Windows 10 and as a precursor they’ve tightened up security and I’ve lost my admin access (therefore MapWinGIS when we update). Because of this I’ve joined those people looking for a way around registering the ActiveX. Turns out that manifest files don’t work with VBA (though to get one to test this I had to compile the project myself - which was a first for me - so I learnt something new!). I then progressed to trying to fiddle with local_user registry keys. That gave me no joy either so I’ve given up and put in a call to the desktop team to get MapWinGIS approved system-wide (every cloud, etc!).

So, the upshot is that I seriously messed with my installation - both registry wise (at least the bits I still have write access to) and also by directly overwriting (without running install) the contents of my c:\dev\MapWinGIS directory with various different releases and home-generated versions. It’s probably my own fault that my system is unstable and it serves me jolly well right. However I DO see that the historical IDs for the tiles class in the part of the registry I can no longer change are not the same as the ones my investigations suggest I should be adding to local_user so I’m wondering (only wondering, mind you, this is WAY out of my comfort zone) if the unique ID for the tiles class has recently changed in the source code? If that’s the case would that explain the error if the registry is stuck with the old class ID?

Back in the office today so I could fiddle with my (presumably dodgy) installation - whilst it’s not worth Jerry’s time solving problems with dodgy installations I do have more interesting observations that may assist dpmcmlxxvi…

Map1.Tiles.AutodetectProxy gives me the “Library Not Registered” error BUT

Dim t As MapWinGIS.Tiles
Set t = Map1.Tiles 'Map1 is the map embedded in the spreadsheet
t.AutodetectProxy

Works just fine - so the “Library Not Registered” error is presumably a bit of a red herring; the main thing seems to be to assign the map object’s tiles to a variable and use that - then the error goes away! I also had the same error/solution for Map1.Shapefile(LayerHandle).numshapes - assigning the shapefile for the layer to a shapefile variable lets me access the numshapes property even though trying it directly gives me the “not registered” error.

@PipzUK

Thanks. That certainly stopped the error messages. Now I just have to start debugging the underlying problem. Thanks again.

Good Catch, @PipzUK.

So this is not the same situation that I had seen before. This is because Office (VBA) treats each of the interfaces as Dispatch (late-bound) interfaces. The current interface does not have enough information to “piggy-back” into the next COM interface. As such, when calling a method from one object that returns an interface to yet another object, you have to set the result into an appropriately typed variable, from which you can then make the call to the next level.

Regards,
Jerry.

But usually it works fine, over the years I’ve run MapWinGIS via VBA on many machines and never had this issue, it’s just one installation where things have unravelled and I’m fascinated to know why - though I’m quite intrigued by your explanation, @jerryfaust , I just wonder what causes the tipping point for it to fail!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.