- 2008年4月25日 07:40
- Excel VBA | Useful Technic
スピンボタンを使って、グラフの高さ(幅)などを設定する簡単なアルゴリズムを紹介します。
Easy algorithm to change Excel Chart Setting by spinbutton.
下記のページは、Spindown & SpinUp イベントを使用した例です。プロシージャが2つになりますので、コマンドボタンを使った時とほぼ同じようになります。
Spinbutton_spindown & spinup event
スピンボタンのプロパティ設定をしておきます。プロパティウィンドウを開いて設定項目の値を変えるとセット出来ます。スピンボタンの値の最大値を1、最小値を-1、値を0に設定します。
アルゴリズムはプロシージャが呼び出されて、グラフの高さ(幅)の設定が終わったときに、値を0に初期化します(SpinButton_ChartHeight.Value=0)。その時、スピンボタンの値が変わるので、もう一度呼び出されます。プロシージャの最初の行にスピンボタンの値が0の場合は、イグジットするようにコードを書いて無駄な処理を省きます。ループで大量のグラフ設定を想定した場合、このやり方は推奨できません。こちらのページにコマンドボタンを使うやり方があります。また、 SpinButton_ChartHeight.Value=0 の部分をSpinButton_ChartHeight.Value = SpinButton_ChartHeight.Value + 1 などと書いてしまうとエラー、または無限ループになるので注意が必要です。
Fistable, set property of spinbutton (value,max,min) as below.
It initializes the value of spinbutton to "0", after a setup finishes. At the same time, procedure is called twice because of initializing the value to "0". Preparing for second time, write code "If CLng(SpinButton_ChartHeight.Value) = 0 Then Exit Sub". Then, useless processing can be excluded. The sample code set up the value of increasing by 10. I donot recomend if you have large number of charts, and using it repeatedly. Also, be careful to error or infinite loop when you write code like "SpinButton_ChartHeight.Value = SpinButton_ChartHeight.Value + 1".
Comments:0
Home > Excel VBA | Useful Technic > Excel グラフの高さ&幅をスピンボタンで設定(Change Height & Width of Excel Chart by Spinbutton)
Search