EXCEL VBA: calling an event with onclick property of a button which is being created on the fly -
i creating excel vba userform requires many buttons created on fly (ie requirement may be, runtime). want assign subroutine these buttons when clicked subroutine should execute.
this want do
set obj4 = usrform.controls.add("forms.commandbutton.1") obj4.height = 17 obj4.left = 450 obj4.top = 75 obj4.font.size = 11 obj4.name = "compare" & (j - i) 'j , variables in code obj4.caption = "compare!" obj4.onclick = abcd public sub abcd() 'some code here end sub
but code not running. read somewhere here cannot call subroutine function. problem want subroutine dont intend in return it. still trial purpose made abcd() function in above code , code running unsuccessfully executing function abcd without need of button getting pressed.
can me this? have searched lot on internet in various forums.
don't hung on subroutine v. function: if don't set return value of function, it's same subroutine.
when set onclick property, give name of function string obj4.onclick = "abcd"
otherwise execute function , save return value.
Comments
Post a Comment