How can I add (dynamically) a macro to each new worksheet created ?
This is the macro to be added :
Private Sub Worksheet_Deactivate()
Sheets("Dynamically Created Name").Visible = False
End Sub
This is the macro that dynamically creates the new worksheets:
Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim l As Long
l = 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
l = l + 1
With wSheet
.Range("A1").Name = "Start_" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Back to Index"
.Cells(2, 1) = "NAME"
.Cells(2, 1).Font.Bold = True
.Cells(2, 1).ColumnWidth = 25
.Cells(2, 2) = "AMT DUE"
.Cells(2, 2).Font.Bold = True
.Cells(2, 2).ColumnWidth = 25
.Cells(2, 3) = "COMMENTS"
.Cells(2, 3).Font.Bold = True
.Cells(2, 3).ColumnWidth = 60
'>>>>>> I believe the added code should go here <<<<<<<<
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(l, 1), Address:="", _
SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
End If
Next wSheet
Sheets("Index").Activate
Sheets("Index").Range("A1").Select
End Sub
The macro will need to 'pick up' the dynamically created worksheet name for insertion into
Sheets("Dynamically Created Name").Visible = False
Thank you for your assistance.
Bookmarks