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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top