Pergunta

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?

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top