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?

Était-ce utile?

La 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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top