Hi there.
I'm trying to make a userform which will come up with a list of all sheets in the workbook (both hidden and unhidden) such that when you click on the name of a sheet the sheet is then selected.
Essentially I'm trying to create a contents page.
The code I have so far will populate the Userform with the names of the sheets:
Sub addLabels()
UserForm1.Show vbModeless
Dim theLabel As Object
Dim n As Long
Dim m As Integer
m = Worksheets.Count
For n = 1 To m
sheetname = Worksheets(n).Name
Set theLabel = UserForm1.Controls.Add("Forms.Label.1", "Sheet" & n, True)
With theLabel
.Caption = sheetname
.Left = 12
.Width = 234
.Top = 40 + 14 * n
End With
Next
End Sub
This code works and the spacing is good. Now I want to add a macro to each label which goes along the lines of :
sub label_n()
if worksheets(n).hidden=true then
worksheets(n).hidden=false
worksheets(n).select
else
worksheets(n).select
end if
end sub
Suggestions on adding this code dynamically?
Bookmarks