troubleshooting Question

adding a procedure to a excel workbook in vb.net

Avatar of LeeHopkins
LeeHopkinsFlag for United States of America asked on
.NET ProgrammingC#Visual Basic.NET
6 Comments1 Solution1001 ViewsLast Modified:
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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros