I have a looping job but with in the looping I want to click the command button using excel vba is this possible -
i have looping job in looping want click command button using excel vba possible?
sub workbook_open() dim c boolean dim choice range dim counter integer application.executeexcel4macro "show.toolbar(""riboon"",true)" sheets("psr").activate if choice = activesheet.shapes.range(array("psrnew")).select psrnew_reqinfo.show c = false else counter = counter + 1 range("a1").value = counter 'application.wait (now + timevalue("00:00:05")) end if loop until c = true end sub
the question here interrupting execution of code , passing control operating system process message queue (where button click event patiently waiting). function doevents
(https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/doevents-function).
how call doevents
entirely you. pretty obviously, more call (ie interrupt own code), slower routine be. there other issues associated doevents
documentation should point in right direction.
as example scenario, you'd need 3 routines: 1 handling button click (if it's activex button, i've presumed code behind sheet containing button), 1 in module consume click event (in sample code, changes module-level flag false), , in module run loop (which ends if flag false). so...
module code
option explicit private mleaveloop boolean public sub main() const limit long = 1000000 dim counter long mleaveloop = false counter = 1 counter = counter + 1 doevents if counter = limit exit 'emergency exit avoid infinite loop loop until mleaveloop debug.print "stopped @ " & counter end sub public sub consumebuttonclick() mleaveloop = true end sub
and sheet code
option explicit private sub commandbutton1_click() consumebuttonclick end sub
Comments
Post a Comment