I need to create the following at runtime in vb.net
Private Sub Workbook_Open()
Application.OnKey "^q", "openForm"
End Sub
in an excel spread sheet.
I can create a Module
Dim oModule As VBIDE.VBComponent
oModule = book.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule)
scode = "Sub openForm()" & vbCr & "Userform1.show" & vbCr & "end sub"
' Add the VBA macro to the new code module.
oModule.CodeModule.AddFromString(scode)
but I need to have the sub in th "Thisworkbook" I know it has some thing to do with vbext_ct_doucment but I cant get to add.
Our community of experts have been thoroughly vetted for their expertise and industry experience.