snuffnchess
Board Regular
- Joined
- May 15, 2015
- Messages
- 71
- Office Version
- 365
- Platform
- 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!!!
(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