Question

I want to autorun a macro whenever I create a new worksheet in a workbook. Below is what I tried:

    Private Sub Workbook_NewSheet()
        Call Macro1
    End Sub

    Sub Macro1()
        ...
        ...
    End Sub

Turns out nothing happened. Why?

Was it helpful?

Solution

I guess you have put them under the wrong place.

Private Sub Workbook_NewSheet(ByVal Sh as Object)
    Call Macro1
End Sub

should be put under ThisWorkBook while

Sub Macro1()
    ...
    ...
End Sub

should be put under Modules

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top