Memo/2004-06-21
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
#contents
*Excel 関連情報 [#x8672b4a]
**サンプルコード [#h63ee22f]
***オートシェイプの使い方 [#q0670af9]
-オートシェイプを使って線を描画するサンプル(その1)
' オートシェイプを使って線を描画するサンプル
' <テストデータ>
' 番号, X軸, Y軸, 経路フラグ(-1の場合、経路なし)
' 1,9,3,-1
' 2,4,7,1
' 3,10,8,-1
' 4,13,5,1
' 5,8,15,1
Sub LineDrawTest()
Const nCount = 5 ' データ件数
Const nScale = 10 ' 倍率
Dim n ' データの番号
Dim x_st ' 線の開始位置(X軸)
Dim y_st ' 線の開始位置(Y軸)
Dim x_ed ' 線の終了位置(X軸)
Dim y_ed ' 線の終了位置(Y軸)
Dim i ' ループカウンタ
Dim flag ' 経路フラグ
Dim line ' オートシェイプ:線
Dim oval ' オートシェイプ:円
Dim text ' オートシェイプ:テキストボックス
For i = 1 To nCount
n = ActiveSheet.Cells(i, 1)
x_ed = ActiveSheet.Cells(i, 2) * nScale
y_ed = ActiveSheet.Cells(i, 3) * nScale
flag = ActiveSheet.Cells(i, 4)
' flag が -1 の場合、経路が無いものとします。
If i = 1 Or flag = -1 Then
x_st = x_ed
y_st = y_ed
Else
End If
With ActiveSheet
' 線を表示(X座標、Y座標、X座標2、Y座標2)
Set line = .Shapes.AddLine(x_st, y_st, x_ed,...
' 点(○)を表示(X座標、Y座標、幅、高さ)
Set oval = .Shapes.AddShape(msoShapeOval, x_...
oval.Fill.ForeColor.SchemeColor = 10 ' 色(...
' 番号を表示(X座標、Y座標、幅、高さ)
Set text = .Shapes.AddTextbox(msoTextOrienta...
text.Select
Selection.Characters.text = CStr(n)
text.Fill.Visible = msoFalse ' 非表示に
text.line.Visible = msoFalse ' 非表示に
End With
x_st = x_ed ' 次回開始位置を指定
y_st = y_ed ' 次回開始位置を指定
Next
End Sub
-実行結果
#ref(hatena_20040621_1.jpg);
-修正版
--[[オートシェイプを使って線を描画するサンプル(その2)>...
-はてな
--http://www.hatena.ne.jp/1087797083
終了行:
#contents
*Excel 関連情報 [#x8672b4a]
**サンプルコード [#h63ee22f]
***オートシェイプの使い方 [#q0670af9]
-オートシェイプを使って線を描画するサンプル(その1)
' オートシェイプを使って線を描画するサンプル
' <テストデータ>
' 番号, X軸, Y軸, 経路フラグ(-1の場合、経路なし)
' 1,9,3,-1
' 2,4,7,1
' 3,10,8,-1
' 4,13,5,1
' 5,8,15,1
Sub LineDrawTest()
Const nCount = 5 ' データ件数
Const nScale = 10 ' 倍率
Dim n ' データの番号
Dim x_st ' 線の開始位置(X軸)
Dim y_st ' 線の開始位置(Y軸)
Dim x_ed ' 線の終了位置(X軸)
Dim y_ed ' 線の終了位置(Y軸)
Dim i ' ループカウンタ
Dim flag ' 経路フラグ
Dim line ' オートシェイプ:線
Dim oval ' オートシェイプ:円
Dim text ' オートシェイプ:テキストボックス
For i = 1 To nCount
n = ActiveSheet.Cells(i, 1)
x_ed = ActiveSheet.Cells(i, 2) * nScale
y_ed = ActiveSheet.Cells(i, 3) * nScale
flag = ActiveSheet.Cells(i, 4)
' flag が -1 の場合、経路が無いものとします。
If i = 1 Or flag = -1 Then
x_st = x_ed
y_st = y_ed
Else
End If
With ActiveSheet
' 線を表示(X座標、Y座標、X座標2、Y座標2)
Set line = .Shapes.AddLine(x_st, y_st, x_ed,...
' 点(○)を表示(X座標、Y座標、幅、高さ)
Set oval = .Shapes.AddShape(msoShapeOval, x_...
oval.Fill.ForeColor.SchemeColor = 10 ' 色(...
' 番号を表示(X座標、Y座標、幅、高さ)
Set text = .Shapes.AddTextbox(msoTextOrienta...
text.Select
Selection.Characters.text = CStr(n)
text.Fill.Visible = msoFalse ' 非表示に
text.line.Visible = msoFalse ' 非表示に
End With
x_st = x_ed ' 次回開始位置を指定
y_st = y_ed ' 次回開始位置を指定
Next
End Sub
-実行結果
#ref(hatena_20040621_1.jpg);
-修正版
--[[オートシェイプを使って線を描画するサンプル(その2)>...
-はてな
--http://www.hatena.ne.jp/1087797083
ページ名: