High Plains Grifter
Board Regular
- Joined
- Mar 9, 2010
- Messages
- 129
Hello all,
I have written a macro which "plots" points on a map. Each point is a msoShapeOval, and I add a hyperlink to each shape, so that the tooltip can display the name of the location and the score associated with that location.
That's all fine, but I have been asked to add functionality to the map so that when any shape is clicked, a display of (for instance) all the points and scores within 50 miles of the click location is returned. I thought the solution was to use the SheetFollowHyperlink() or FollowHyperlink() event, but neither of these seem to trigger when I click on any of the shapes, although hyperlinks in cells trigger the event. I am new to these events, but is this expected behaviour?
If this is not the way run a macro which takes the shape name as a variable when the user clicks on a shape, is there an alternative? (I would like to keep the tooltips on the shapes if at all possible, which makes the SelectionChange event unusable?)
All suggestions most welcome - thanks for taking the time to read this!
Mark
Here is the code for putting the points on the map.
I have written a macro which "plots" points on a map. Each point is a msoShapeOval, and I add a hyperlink to each shape, so that the tooltip can display the name of the location and the score associated with that location.
That's all fine, but I have been asked to add functionality to the map so that when any shape is clicked, a display of (for instance) all the points and scores within 50 miles of the click location is returned. I thought the solution was to use the SheetFollowHyperlink() or FollowHyperlink() event, but neither of these seem to trigger when I click on any of the shapes, although hyperlinks in cells trigger the event. I am new to these events, but is this expected behaviour?
If this is not the way run a macro which takes the shape name as a variable when the user clicks on a shape, is there an alternative? (I would like to keep the tooltips on the shapes if at all possible, which makes the SelectionChange event unusable?)
All suggestions most welcome - thanks for taking the time to read this!
Mark
Here is the code for putting the points on the map.
Code:
Sub MapMan()Dim rCell As Range
Dim rRng As Range
Dim ws As Worksheet
'Dim iMAXCount As Integer
Dim iCount As Byte
Dim shp As Object
Dim pic As Object
Set ws = Sheets("All Locations")
Set rRng = Range("Counts")
ws.Unprotect
For Each shp In ws.Shapes
If shp.Name = "WorldMap" Or shp.Name = "Button 4" Then
'do nothing
Else
shp.Delete
End If
Next
For Each rCell In rRng
iCount = Round(rCell.Offset(0, 5).Value / Range("MaxCount").Value * 255, 0)
Set shp = ws.Shapes.AddShape(msoShapeOval, (rCell.Offset(0, 3).Value * 7.48) - 90, (rCell.Offset(0, 4).Value * -7.48) + 957, 10, 10)
With shp.Fill
.ForeColor.RGB = udf_RGB(iCount, iCount, iCount, "Dragon", False)
'.Transparency = 0.5
.Transparency = 0
.Solid
.Visible = msoTrue
End With
shp.Line.Visible = msoFalse
ws.Hyperlinks.Add Anchor:=shp, Address:="", ScreenTip:=" " + _
Application.WorksheetFunction.Proper(rCell.Offset(0, -1).Value) + _
" (" + Str(rCell.Offset(0, 5).Value) + ")"
Next
ws.Protect
End Sub
Code:
Function udf_RGB(myR As Byte, myG As Byte, myB As Byte, Optional ColourMap As String = "Black and White", Optional Reverse As Boolean = False) As Long
If Reverse = True Then
myR = 255 - myR
myG = 255 - myG
myB = 255 - myB
Else
'nothing
End If
Select Case ColourMap
Case "Black and White"
udf_RGB = RGB(myR, myG, myB)
Case "Red"
udf_RGB = RGB(255, myG, myB)
Case "Green"
udf_RGB = RGB(myR, 255, myB)
Case "Blue"
udf_RGB = RGB(myR, myG, 255)
Case "Neon"
udf_RGB = RGB(Application.WorksheetFunction.Min(255, (255 - myR) * 2), Application.WorksheetFunction.Min(myG * 2, 255), Application.WorksheetFunction.Max(255 - myB, 255 + (myB - 255)))
Case "Dragon"
udf_RGB = RGB(255, 255 - myG, 0)
Case "Hot Coals"
udf_RGB = RGB(Application.WorksheetFunction.Min(myR * 2, 255), Application.WorksheetFunction.Min(2 * myG, 2 * (255 - myG)), 0)
Case "Traffic Lights"
udf_RGB = RGB(Application.WorksheetFunction.Min(255, (255 - myR) * 2), Application.WorksheetFunction.Min(myG * 2, 255), 0)
Case "Starburst"
udf_RGB = RGB(Application.WorksheetFunction.Min(myR * 2, 255), Application.WorksheetFunction.Min(myR * 2, (255 - myR) * 2), 0)
End Select
End Function