Hi,
I am working on an Excel VBA based app that uses MapPoint to display two postcodes and will draw a line between the two. The color and weight of that line is selected from an excel userform and the result stored in a hidden sheet along with some other bits and bobs.
The problem that I've been struggling for the last 48 hours relates to programatically setting the line color. I'm using the color constants described on MSDN Using Shape Color Values in MapPoint. Relevant code is below. I'm getting type mismatches between the string value as a result of the vlookup (tried mpBlack and the &H1& values as the lookup result) Manually coding line.forecolor = mpblack works fine.
Other things I've tried:
1. using forecolor.schemecolor
2. forecolor.RGBCode:shape.line.forecolor.SchemeColor = 2 'should be pink/purple
If the code doesn't error then I only get black lines (or in one case Olive, regardless of the value passed in the statement).Code:shape.line.forecolor.RGB= FF00FF
I've been googling and even the microsoft object model is scant on detail around the shape.line methods/ properties. There is C# based information but this focusses on using the System.Drawing namespace and defining a color variable. Something not possible in VBA AFAIK. I also can't find a VBA way to cast a string to a color...Code:Dim oApp, oMap As Object Set oApp = GetObject(, "MapPoint.Application") oApp.Units = geoKm oApp.ActiveMap.MapStyle = geoMapStyleData 'set up variables Dim oLocA, oLocB As MapPoint.Location Dim strSitePcdeA, strSitePcdeB, strColour, strWeight As String Dim strLineName As String 'get the submitted color strColour = Application.WorksheetFunction.VLookup(strSiteBw, Sheets("Circuits").Range("A2", Sheets("Circuits").Range("C65534").End(xlUp)), 2, False) If strColour = "<Select Colour>" Then strColour = "Black" 'convert to the MP colour strColour = Application.WorksheetFunction.VLookup(strColour, Sheets("Lines").Range("A1", Sheets("Lines").Range("B65534").End(xlUp)), 2, False) Set oMap = GetObject(, "MapPoint.Application").ActiveMap 'query mappoint for locations Set oLocA = oMap.FindAddressResults(, , , , strSitePcdeA)(1) Set oLocB = oMap.FindAddressResults(, , , , strSitePcdeB)(1) 'draw the line oMap.Shapes.AddLine(oLocA, oLocB).Name = strLineName With oMap.Shapes.Item(strLineName) .ZOrder geoSendBehindRoads .Line.ForeColor = strColour .Line.Weight = strWeight End With Set oLocA = Nothing Set oLocB = Nothing oMap.DataSets.ZoomTo 'zoom to datasets when displaying map oApp.Visible = True
I'm sure this is something that can be sorted quite simply so any assistance / direction /advice would be greatfully received.
Thanks for your time and help.
Cheers
Matt




LinkBack URL
About LinkBacks






Reply With Quote

