Results 1 to 2 of 2

Thread: Adding Event Macro to a Command Button at Run-time causes VB Editor to Pop-up

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    1

    Adding Event Macro to a Command Button at Run-time causes VB Editor to Pop-up

    I'm using Excel 2003 SP2.

    The premise is I add worksheets at run-time based off of user actions. The sheets then add command buttons and then assign some vb code to be fired when clicked. Everything works great except the VB editor pops up (even when its closed). This is annoying, any way to stop it from doing so?

    VB Code:
    1. Public Sub Test(myWS As Excel.Worksheet)
    2.     Dim OLEObj As OLEObject
    3.     Dim Rng As Range
    4.     Dim WS As Worksheet
    5.     Dim CodeMod As Object
    6.     Dim LineNum As Long
    7.    
    8.     Set WS = myWS
    9.     Set Rng = Range("I13")
    10.        
    11.     Set OLEObj = _
    12.     WS.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
    13.         Top:=Rng.Top, Left:=Rng.Left, Height:=Rng.Height * 2, _
    14.         Width:=Rng.Width * 2)
    15.     OLEObj.name = "test"
    16.     OLEObj.Object.Caption = "test"
    17.     Set CodeMod = _
    18.     ThisWorkbook.VBProject.VBComponents(WS.CodeName).CodeModule
    19.     LineNum = CodeMod.CreateEventProc("Click", OLEObj.name)
    20.     CodeMod.insertLines LineNum + 1, _
    21.         "msgbox(""test"")"        
    22. End Sub

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Adding Event Macro to a Command Button at Run-time causes VB Editor to Pop-up

    Moved to Office Development forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width