![]() |
parameter
I have a Userform.
the userform have 9 button. cmdBtn1, cmdBtn2, .... cmdBtn9 that buttons have a procedure respectively. I want to run the button procedure using loop. for example, for i=1 to 9 application.run "cmdBtn" & i next but debug.... How can I..... *** Sent via Developersdex http://www.developersdex.com *** |
parameter
If you are going to run nine procedures consecutively, then why not take them
out of the controls, rename them and put them in a module. Then you can create a master procedure that calls the nine, as in the example below: Sub master() macro1 macro2 ... macro9 End Sub Or, if you need to use a command button, then call them all from one button's click event in a similar manner as the example above. "x taol" wrote: I have a Userform. the userform have 9 button. cmdBtn1, cmdBtn2, .... cmdBtn9 that buttons have a procedure respectively. I want to run the button procedure using loop. for example, for i=1 to 9 application.run "cmdBtn" & i next but debug.... How can I..... *** Sent via Developersdex http://www.developersdex.com *** |
parameter
What you can do is shift the code for each button to a module and then call
the sub in the module when the individual button is clicked. Examples:- Private Sub cmdBtn1_Click() Call modCmdBtn1 End Sub Private Sub cmdBtn2_Click() Call modCmdBtn2 End Sub In the module you then set your subs up as per this example:- Sub modCmdBtn1() MsgBox "This is modCmdBtn1()" 'Used this for testing End Sub Sub modCmdBtn2() MsgBox "This is modCmdBtn2()" End Sub The following if attached to a button will call each of the subs in the module using the For/Next routine. Private Sub RunCode_Click() For i = 1 To 9 strSubName = "modCmdBtn" & i Application.Run (strSubName) Next i End Sub -- Regards, OssieMac "JLGWhiz" wrote: If you are going to run nine procedures consecutively, then why not take them out of the controls, rename them and put them in a module. Then you can create a master procedure that calls the nine, as in the example below: Sub master() macro1 macro2 ... macro9 End Sub Or, if you need to use a command button, then call them all from one button's click event in a similar manner as the example above. "x taol" wrote: I have a Userform. the userform have 9 button. cmdBtn1, cmdBtn2, .... cmdBtn9 that buttons have a procedure respectively. I want to run the button procedure using loop. for example, for i=1 to 9 application.run "cmdBtn" & i next but debug.... How can I..... *** Sent via Developersdex http://www.developersdex.com *** |
All times are GMT +1. The time now is 04:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com