found code from davesexcel which needs not to add a new worksheet. Although the Worksheet name is seen in the debugger it errors on line shown. It will complete if adding a new worksheet.
Sub copySheetModule()
Dim DstCmod As VBIDE.CodeModule
Dim xLine As Long
Set DstCmod = ActiveWorkbook.VBProject.VBComponents(ws.Name).CodeModule '''''''''''''''''''''''''''''''''Error here although sees correct ws
With DstCmod
xLine = .CreateEventProc("SelectionChange", "Worksheet")
xLine = xLine + 1
.InsertLines xLine, " Dim Lrow As Long"
xLine = xLine + 1
.InsertLines xLine, " With ActiveSheet"
xLine = xLine + 1
.InsertLines xLine, " Lrow = .Range(""a"" & Rows.Count).End(xlUp).Row"
xLine = xLine + 1
.InsertLines xLine, " If Not Intersect(Target, Range(""A1:a"" & Lrow)) Is Nothing Then"
xLine = xLine + 1
.InsertLines xLine, " Target.Copy"
xLine = xLine + 1
.InsertLines xLine, " End If"
End With
End Sub
Bookmarks