문제

I have a userform with 25 OptionButton (OptionButton1, OptionButton2, etc..)

As it is, to have each of these options called, I created private subs OptionButton1_Click, OptionButton2_Click, etc..

Is there any way to access the different options without creating 25 different subs? (i.e. OptionButton[x]_Click)

도움이 되었습니까?

해결책

I think the short answer is no, but have a look here for an interesting work-around. You could essentially fake a control array.

Besides what is mentioned in the post, you may additionally want to consider storing some kind of Tag in the OptionButton.Tag so that when it is clicked you can (if you wish) know which OptionButton was clicked.

다른 팁

You could loop through all the option buttons. For example:

for i = 1 to 25

    If Controls("OptionButton" & i).Value = True Then

       'perform operation if OptionButton is clicked

     End If

Next i
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top