Print side | Luk vindue

Indholdsfortegnelse

Udskrevet fra: Dansk Regneark Forum
Kategori: Hjælp til regneark.
Forum navn: Makro og VBA
Forum beskrivelse: Hjælp til Makroer og VBA-programmering
Web-adresse: https://forum.excel-regneark.dk/forum_posts.asp?TID=3655
Udskrevet den: 05.Dec.2026 kl. 09:45


Emne: Indholdsfortegnelse
Besked fra: Krogstrup
Emne: Indholdsfortegnelse
Posteringsdato: 20.Okt.2018 kl. 23:14
Jeg bruger denne kode til at lave indholdsfortegnelser i mine regneark, men kunne godt tænkte mig at den sorterede det i alfabestik rækkefølje. Er der nogle som kan hjælpe med det?

Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim M As Long
M = 1
    With Me
        .Columns(1).ClearContents
        .Cells(1, 1) = "Indholdsfortegnelse"
        .Cells(1, 1).Name = "Indholdsfortegnelse"
    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:="Tilbage til indholdsfortegnelsen"
        End With
            Me.Hyperlinks.Add Anchor:=Me.Cells(M, 1), Address:="", SubAddress:="Start" & wSheet.Index, TextToDisplay:=wSheet.Name
        End If
        Next wSheet
End Sub



Svar:
Besked fra: maxzpad
Posteringsdato: 22.Okt.2018 kl. 09:35
Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim M As Long
M = 1
    With Me
        .Columns(1).ClearContents
        .Cells(1, 1) = "Indholdsfortegnelse"
        .Cells(1, 1).Name = "Indholdsfortegnelse"
    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:="Tilbage til indholdsfortegnelsen"
        End With
            Me.Hyperlinks.Add Anchor:=Me.Cells(M, 1), Address:="", SubAddress:="Start" & wSheet.Index, TextToDisplay:=wSheet.Name
        End If
        Next wSheet
        
    With Me
        
        With .Sort
        
            With .SortFields
        
                .Clear
                .Add Key:=Me.Range("A2:A" & M), _
                     SortOn:=xlSortOnValues, Order:=xlAscending, _
                     DataOption:=xlSortNormal
            
            End With
        
            .SetRange Me.Range("A2:A" & M)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        
        End With
        
    End With
    
End Sub




Print side | Luk vindue