Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Misty Perez   on Mar 21 In MS Office Category.

  
Question Answered By: Rachael Ferguson   on Mar 21

Absolutely.
Place this code in the ThisWorkbook module:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim NewSheet As Worksheet
Set NewSheet = Sheets(ActiveSheet.Name)
Code = "Private Sub Worksheet_Change(ByVal Target As Range)" & vbCrLf
Code = Code & "MsgBox ""your code here""" & vbCrLf
Code = Code & "End Sub"
With ThisWorkbook.VBProject.VBComponents(NewSheet.Name).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

On addition of a new sheet to the workbook it places these three lines
of code in the new sheet's code module:

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "your code here"
End Sub

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Adding a Worksheet_Event when adding a worksheet via VBA Or get search suggestion and latest updates.


Tagged: