Consulting

Results 1 to 3 of 3

Thread: Solved: OLEObject Click Event

  1. #1
    VBAX Newbie
    Joined
    Mar 2009
    Posts
    5
    Location

    Solved: OLEObject Click Event

    Hi all!
    I stumbled upon just another issue where google right now couldn't help me:

    In an excel file I generate an ActiveX CommandButton dynamically via program code. Now I want to program a Click-procedure for this single button. How do I have to do it? For example, the name of the button is "CmdOk"
    (Please forgive me as this question may be just a noobie's one...)

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,438
    Location
    [vba]

    Dim StartLine As Long

    With ActiveWorkbook.VBProject.VBComponents("Sheet1").CodeModule
    StartLine = .CreateEventProc("Click", "CommandButton1") + 1
    .InsertLines StartLine, _
    "Dim ans" & vbCrLf & _
    " ans = Msgbox( ""All OK"",vbYesNo)" & vbCrLf & _
    " If ans = vbNo Then Cancel = True"
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Mar 2009
    Posts
    5
    Location
    Thanks a lot. That is exactly what I was looking for! And please excuse me, if those questions were bugging or annoying someone!

Posting Permissions

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