重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

【GOLF me!】初月無料お試し

ユーザーフォーム上にたくさんのボタンを配置しているのですが、
すべて同じ動作なので、一つにまとめたいです。
どのように記述したらよいでしょうか?

Private Sub CommandButton1_Click()
Selection.Interior.color = select_Color
End Sub

Private Sub CommandButton2_Click()
Selection.Interior.color = select_Color
End Sub

Private Sub CommandButton3_Click()
Selection.Interior.color = select_Color
End Sub

Private Sub CommandButton4_Click()
Selection.Interior.color = select_Color
End Sub

A 回答 (2件)

ふつーにやっていては出来ないことなので,次の資料を参考にして作成してください。


http://www.asahi-net.or.jp/~ef2o-inue/vba_o/sub0 …
    • good
    • 0

>まとめて、



ボタン4つで動作はどこか1か所で記述

Private Sub CommandButton1_Click()
call sele_color
End Sub

Private Sub sele_color()
Selection.Interior.color = select_Color
End Sub

こういう記述?。

この回答への補足

いえ、ボタンは20個くらいあります。

補足日時:2011/02/28 00:29
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!