Create link to Index tab and put on every worksheet

snuffnchess

Board Regular
Joined
May 15, 2015
Messages
71
Office Version
  1. 365
Platform
  1. Windows
I am currently running the following code every time the workbook opens.... and I am needing to also create a link to the "Index" page on each of the worksheets as well

(Would put the link in cell "H1" of each worksheet)

When I run the below code I get an "Application-defined or Object Defined error" on the "Activesheet.Hyperlinks.Add" line... but not sure how to fix it? help!!!

VBA Code:
Sub CreateIndex()
'updateby Extendoffice
    Dim xAlerts As Boolean
    Dim I  As Long
    Dim xShtIndex As Worksheet
    Dim xSht As Variant
    Dim ws As Worksheet
    
    
    
    
    
    
    
    
    Application.ScreenUpdating = False
    xAlerts = Application.DisplayAlerts
    Application.DisplayAlerts = False
    
    On Error Resume Next
    Sheets("Index").Delete
    On Error GoTo 0


    
    
    
    
    
    Set xShtIndex = Sheets.Add(Sheets(1))
    xShtIndex.Name = "Index"
    I = 1
    Cells(1, 1).Value = "INDEX"
    For Each xSht In ThisWorkbook.Sheets
        If xSht.Name <> "Index" Then
            I = I + 1
            xShtIndex.Hyperlinks.Add Cells(I, 1), "", "'" & xSht.Name & "'!A1", , xSht.Name
        End If
    Next
    
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> "Index" Then
            ws.Activate
            ActiveWindow.Zoom = 100
            ActiveSheet.Hyperlinks.Add Range("H1"), Address:="", SubAddress:="'" & xShtIndex.Name & "'!A1", TextToDisplay:="Return To Index"
            'ActiveSheet.Hyperlinks.Add Cells(1, 8), "", "'" & xShtIndex.Name & "'!A1", , "Return to Index"
        End If
    Next
    
    
    
    Cells.Select
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
    Cells.EntireColumn.AutoFit
    Range("A1").Select
    
    
    Application.DisplayAlerts = xAlerts
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
As a side note, I have tried also using the format of

VBA Code:
ActiveSheet.Hyperlinks.Add Cells(1, 8), "", "'" & xShtIndex.Name & "'!A1", , "Return to Index"

And I get the same error
 
Upvote 0
Final update - so sorry. The code will run for 5 worksheets and then fail on the 6th one... which is odd.
 
Upvote 0
nevermind... I am dumb - there was a locked worksheet. Everything is working.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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