Dynamic Table of contents exclusions

XrayLemi

Board Regular
Joined
Aug 1, 2018
Messages
153
Office Version
  1. 365
Platform
  1. Windows
Hello All,
I have the following code that creates a Dynamic list of worksheets in my workbook. It works "Okay" but needs some finesse.

In the code is This Line
VBA Code:
  If sht.CodeName <> "Sheet29" Then
It Excludes The Table of Contents page from the list. This Works Fine.

I would also like it to exclude any worksheet that has the property
. Visible = xlSheetVeryHidden
This is what I tried
VBA Code:
If sht.CodeName <> "Sheet29" Or sht.Visible = xlSheetVeryHidden Then
But it didn't work. No errors, just didn't work. Sheet29 is omitted but any sheet that is xlSheetVeryHidden still makes the list.

Any help would be greatly appreciated! Here is the entire code
VBA Code:
Private Sub Worksheet_Activate()

Dim sht As Worksheet
Dim TOCsht As Worksheet
Dim RowNo As Integer

Set TOCsht = Sheet29
TOCsht.Unprotect Password:="Password"
TOCsht.Cells.Clear

With TOCsht.Cells(1, 1)
    .Value = "Index"
    .Font.Bold = True
    .Font.Size = 20
    .HorizontalAlignment = xlCenter
End With

RowNo = 1

For Each sht In ThisWorkbook.Worksheets
    If sht.CodeName <> "Sheet29" Or sht.Visible = xlSheetVeryHidden Then
        RowNo = RowNo + 1
        TOCsht.Cells(RowNo, 1).Hyperlinks.Add _
        Anchor:=Cells(RowNo, 1), _
        Address:="", SubAddress:="'" & sht.Name & "'!A1", _
        ScreenTip:="", _
        TextToDisplay:=sht.Name
    End If
Next sht

Dim r As Range, c As Range
Set r = Range(Range("A2"), Range("A2").End(xlDown))
For Each c In r
With c.Font
        .Size = 12
End With
Next

End Sub

Thank you in advance,
Jim
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Okay, no takers. That's okay, I finally figured something out for my self.

I changed This line
VBA Code:
If sht.CodeName <> "Sheet29" Or sht.Visible = xlSheetVeryHidden Then

To this
VBA Code:
If sht.CodeName <> "Sheet29" And sht.Visible <> xlSheetVeryHidden Then

Now it works fine!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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