Turning a table of contents built via a VBA Worksheet_Activate sub-routine into a set of clickable links to the other worksheets within the workbook

cuddling101

New Member
Joined
Feb 10, 2009
Messages
34
I am trying to turn a worksheet that is, in effect, a table of contents into a set of links to each of the respective worksheets.

I have the following working Activate_Worksheet event sub-routine -

Code:
Private Sub Worksheet_Activate()
    
    Dim wb As Workbook
    Dim ws() As Worksheet
    Dim rng As Range
    Dim rngNow As Range
    Dim wsCount As Integer
    Dim wsColor() As String
    Dim wsPrime As Worksheet

    Dim I As Long
    
    Set wb = ThisWorkbook
    Set wsPrime = wb.Worksheets("Coverage_Statistics") 'Targets Coverage_Statistics for placement of Table of Contents
    
    wsCount = wb.Names("Main_Families_Count").RefersToRange.Value
        
    Set rng = wsPrime.Range("A1:B" & wsCount)
    ReDim ws(1 To wsCount)
    ReDim wsColor(1 To wsCount)
    
    For I = 1 To wsCount
    
        Set ws(I) = Worksheets(I)
        wsColor(I) = ws(I).Tab.Color
        Set rngNow = rng(I + 1, 1)
        rngNow.Interior.Color = wsColor(I)
        rngNow = ws(I).Name
        
    Next I
    
End Sub

I am now trying to not just simply apply the values in ws(I).Name into their appropriate cells, but to make the sheet just a little more helpful by making the cell a clickable link.

I did some net searching and found a lot of what I read very hard to understand, but a fairly simple approach did seem to be to just make the cell a hyperlink with a display text, so I tried the following amendments -

Additional declarations

Code:
    Dim rngNowName As String
    Dim rngNowLink As String

Cell contents assignment line, i.e. rngNow = ws(I).Name replaced with

Code:
        rngNowName = ws(I).Name
        rngNowLink = "#" & rngNowName & "!A2"
        rngNow = Application.WorksheetFunction.Hyperlink(rngNowLink, rngNowName)

but I got a Run-time error 438 - Object doesn't support this property or method.

I did see online a thread that included the following code as the link, but I did not understand it, and could not see how to adapt it into my situation. If this, or similar, is the way I have to go, would the kind person who answers this plea for help, explain to me, in dummy speak, the purpose of each part of the command, and give me the correct version, using my variables, as shown above, for my situation.

Code:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'" & wSheet.Name & "'" & "!A1", TextToDisplay:=wSheet.Name

With thanks in anticipation.

Philip
Bendigo, Victoria
Australia
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this:

Code:
rngNow = ws(I).Name
   [COLOR=#0000ff] ActiveSheet.Hyperlinks.Add Anchor:=rngNow, Address:="", SubAddress:= _
        "the-appropriate-sheet!A1", TextToDisplay:=rngNow.value[/COLOR]  [COLOR=#ff0000]<- What is the appropriate sheet? You need to fill it in. Something like "Sheet[/COLOR][COLOR=#ff0000]2"[/COLOR].
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top