A colleague of mine often tends to have quite large sheets with various datasets scattered around it, some of which have associated charts. Maybe not good practise, but that's his problem. He finds it a bit of a pain nevigating quickly to any given chart, if it is somewhere off the displayed area.
He asked me if there was any easy way of listing and finding charts. I suggested using F5, objects, tab - which works fine, but it got me thinking. I'd like to be able to be able to add a new button to an existing add-in toolbar which would run a macro to create a list of all the charts on the active sheet and include hyperlinks to them.
So far, i've got the following code:
This creates the list of charts, and hyperlinks to the cell at the top-left of the chart. This is almost what I was after, and I suppose will do, but does anyone know how I could make the chart itself the target of the hyperlink? I've tried using the chart name in the subaddress instead of the cell reference, but that does not work.
Tony
He asked me if there was any easy way of listing and finding charts. I suggested using F5, objects, tab - which works fine, but it got me thinking. I'd like to be able to be able to add a new button to an existing add-in toolbar which would run a macro to create a list of all the charts on the active sheet and include hyperlinks to them.
So far, i've got the following code:
Code:
Sub CreateChartsIndex()
Dim i As Long, numcharts As Long
Dim Hanchor As Range, Haddress As String, Hsubaddress As String
Dim shtname As String
Dim h As Hyperlink
numcharts = ActiveSheet.ChartObjects.Count
startrow = ActiveCell.Row
startcol = ActiveCell.Column
ActiveCell = "Chart Title"
For i = 1 To numcharts
Cells(startrow + i, startcol) = ActiveSheet.ChartObjects(i).Chart.ChartTitle.Text
shtname = ActiveSheet.ChartObjects(i).Parent.Name
Hsubaddress = Replace(ActiveSheet.ChartObjects(i).TopLeftCell.Address, "$", "")
If Cells(startrow + i, startcol).Hyperlinks.Count > 0 Then
For Each h In Cells(startrow + i, startcol).Hyperlinks
h.Delete
Next h
End If
Set Hanchor = Cells(startrow + i, startcol)
Haddress = shtname
Hsubaddress = Haddress & "!" & Hsubaddress
ActiveSheet.Hyperlinks.Add anchor:=Hanchor, Address:="", subaddress:=Hsubaddress
Next i
End Sub
This creates the list of charts, and hyperlinks to the cell at the top-left of the chart. This is almost what I was after, and I suppose will do, but does anyone know how I could make the chart itself the target of the hyperlink? I've tried using the chart name in the subaddress instead of the cell reference, but that does not work.
Tony