简体   繁体   中英

Trigger a macro on new sheet addition

I have vba code for insert sheet button click

Sheets.Add After:=ActiveSheet

How to transform it to

IF Sheets.Add After:=ActiveSheet THEN {Statement}

You can use the Workbook.NewSheet event.
https://learn.microsoft.com/en-us/office/vba/api/excel.workbook.newsheet

Insert it behind the ThisWorkBook object.

Private Sub Workbook_NewSheet(ByVal Sh As Object)
    'some code
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM