Userform Command Button

In a Userform, I have multiple command buttons.  For example:

D1_Click
D2_Click

Depending on another event that occurs, I want to calculate in code the 
button name that I will be triggering the click event and then trigger the 
event.

For example Application.Run "D" & i & "_Click"

with i being the value of 1 or 2.

Application.Run doesn't appear to work in the Userform.

Thanks

Steve
0
Utf
2/26/2010 8:32:03 PM
excel.programming 6508 articles. 2 followers. Follow

3 Replies
1516 Views

Similar Articles

[PageSpeed] 20

Maybe it's because most subroutines in a userform module
are "Private"???   Have you tried changing the "Private"
prefix to "Public" for the D?_Click subroutines??  Maybe
that might fix it......

Also, im not entirely sure if changing routines from Private
to Public is a good idea for userform subroutines.  Maybe
you can place your D?_Click code in a normal module
instead???


"sarndt" <sarndt@discussions.microsoft.com> wrote in message 
news:F96922B7-B52E-4530-B053-1148FB6E9B55@microsoft.com...
> In a Userform, I have multiple command buttons.  For example:
>
> D1_Click
> D2_Click
>
> Depending on another event that occurs, I want to calculate in code the
> button name that I will be triggering the click event and then trigger the
> event.
>
> For example Application.Run "D" & i & "_Click"
>
> with i being the value of 1 or 2.
>
> Application.Run doesn't appear to work in the Userform.
>
> Thanks
>
> Steve 

0
Robert
2/26/2010 9:03:33 PM
I tried changing it to Public and that didn't work.  And Application.Run only 
appears to work with a macro.

"Robert Crandal" wrote:

> Maybe it's because most subroutines in a userform module
> are "Private"???   Have you tried changing the "Private"
> prefix to "Public" for the D?_Click subroutines??  Maybe
> that might fix it......
> 
> Also, im not entirely sure if changing routines from Private
> to Public is a good idea for userform subroutines.  Maybe
> you can place your D?_Click code in a normal module
> instead???
> 
> 
> "sarndt" <sarndt@discussions.microsoft.com> wrote in message 
> news:F96922B7-B52E-4530-B053-1148FB6E9B55@microsoft.com...
> > In a Userform, I have multiple command buttons.  For example:
> >
> > D1_Click
> > D2_Click
> >
> > Depending on another event that occurs, I want to calculate in code the
> > button name that I will be triggering the click event and then trigger the
> > event.
> >
> > For example Application.Run "D" & i & "_Click"
> >
> > with i being the value of 1 or 2.
> >
> > Application.Run doesn't appear to work in the Userform.
> >
> > Thanks
> >
> > Steve 
> 
> .
> 
0
Utf
2/26/2010 10:10:01 PM
Use CallByName. E.g.,

Dim S As String 
S = "CommandButton1_Click"
CallByName UserForm1, S, VbMethod

The CommandButton1_Click must be declared as Public.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
	Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Fri, 26 Feb 2010 12:32:03 -0800, sarndt
<sarndt@discussions.microsoft.com> wrote:

>In a Userform, I have multiple command buttons.  For example:
>
>D1_Click
>D2_Click
>
>Depending on another event that occurs, I want to calculate in code the 
>button name that I will be triggering the click event and then trigger the 
>event.
>
>For example Application.Run "D" & i & "_Click"
>
>with i being the value of 1 or 2.
>
>Application.Run doesn't appear to work in the Userform.
>
>Thanks
>
>Steve
0
Chip
2/26/2010 10:33:33 PM
Reply:

Similar Artilces: