Userform Command Button

S

sarndt

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
 
R

Robert Crandal

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???
 
S

sarndt

I tried changing it to Public and that didn't work. And Application.Run only
appears to work with a macro.
 
C

Chip Pearson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top