Mit folgendem Code wird bisher beim Öffnen des Blatts eine Liste alles Blätter mit jeweiligem Hyperlink erstellt. Da dies aber bei vielen Blättern SEHR lange dauert, möchte ich den Code statt als Workbook.Open-Event lieber über einen Knopf bei Bedarf ausführen.
Das Problem: Excel spuckt nur die Fehlermeldung "Unzulässige Verwendung des Schlüsselworts Me" aus sobald der Code nicht mehr im Workbook.Open-Event steht.
Ich hoffe ihr könnt mir weiterhelfen :)
Hier der Code:
Private Sub Worksheet_Activate()
Sheets("Index").Unprotect Password:="123"
'Define variables
Dim ws As Worksheet
Dim row As Long
row = 1
'Clear the previous list and add "INDEX" title
With Me
.Columns(1).ClearContents
.Cells(1, 1) = "INDEX"
End With
'Loop through each sheet to add a corresponding hyperlink by using the name of the worksheet
For Each ws In Worksheets
If ws.Name Me.Name And ws.Visible = xlSheetVisible Then
row = row + 1
Me.Hyperlinks.Add Anchor:=Me.Cells(row, 1), _
Address:="", _
SubAddress:="'" & ws.Name & "'!A1", _
ScreenTip:="Click to go to sheet " & ws.Name, _
TextToDisplay:=ws.Name
End If
Next ws
'Adjust the width of first column by the longest worksheet name
'Me.Columns(1).AutoFit
Sheets("Index").Protect Password:="123"
End Sub