View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Mills Ray Mills is offline
external usenet poster
 
Posts: 1
Default Help.. Add an event to a sheet module

I am dying here...I am trying to add an event to a sheet module
I tested the code below which adds an open event to ThisWorkbook module
and works great. "The CodeModule object has a method called
CreateEventProc that you can use to create an event procedure in class
module, a sheet"
but i just cant figure how change the "ThisWorkbook" to a sheet moule

Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("Open", "Workbook") + 1
.InsertLines StartLine, _
"Msgbox ""Hello World"",vbOkOnly"
End With