La munca lucrez foarte mult cu Excel si din aceasta cauza am unele workbook-uri foarte mari (aproape 50 sheet-uri).
Am cautat foarte mult un cod care sa mi le indexeze pentru a le putea accesa mai usor.
Codul de mai jos face acest lucru foarte bine.
Cum functioneaza:
- trebuie creat un worksheet nou si redenumit in Index;
- pentru a adauga codul pentru acest sheet se face astfel:
- click dreapta pe sheet-ul numit Index si se alege optiunea View code;
- copiati codul de mai jos in fereastra de cod;
- salvati fisierul Excel si inchideti-l.
Acum de fiecare data cand deschideti acel workbook, in foaia numita Index o sa apara scrise toate sheet-urile existente in acel workbook.
Acum cu un singur click ajungeti in ce sheet doriti.
Pentru a va intoarce pe sheet-ul Index trebuie doar sa dati un click pe textul scris in celula A1 numit Back to Index
Cod: Selectaţi tot
Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim M As Long
M = 1
With Me
.Columns(1).ClearContents
.Cells(1, 1) = "INDEX"
.Cells(1, 1).Name = "Index"
End With
For Each wSheet In Worksheets
If wSheet.Name <> Me.Name Then
M = M + 1
With wSheet
.Range("A1").Name = "Start" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), address:="", SubAddress:="Index", TextToDisplay:="Back to Index"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(M, 1), address:="", SubAddress:="Start" & wSheet.Index, TextToDisplay:=wSheet.Name
End If
Next wSheet
End Sub