Public Class Form1
Dim x1, y1 As Integer
Dim x2, y2 As Integer
Dim app As Excel.Application
Dim wb As Excel.Workbook
Dim sh1 As Excel.Worksheet
Dim cr1, cr2 As Excel.Shape
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If app Is Nothing Then
app = New Excel.Application
Else
Exit Sub
End If
x1 = 0
x2 = 0
y1 = 100
y2 = 200
app.Visible = True
Try
wb = app.Workbooks.Add
Catch ex As Exception
app.Quit()
app = Nothing
Exit Sub
End Try
Try
sh1 = wb.Worksheets(1)
With sh1
cr1 = .Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeOval, x1, y1, 100, 100)
cr2 = .Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeOval, x2, y2, 150, 150)
cr1.Fill.ForeColor.RGB = RGB(255, 0, 0)
cr2.Fill.ForeColor.RGB = RGB(0, 255, 0)
End With
Catch ex As Exception
wb.Close()
app.Quit()
app = Nothing
Exit Sub
End Try
Timer1.Start()
Timer2.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
x1 = x1 + 1
If x1 > 800 Then x1 = 0
cr1.Left = x1
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
x2 = x2 + 1
If x2 > 800 Then x2 = 0
cr2.Left = x2
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
Timer2.Stop()
wb.Close()
app.Quit()
app = Nothing
End Sub
End Class
|
基本的なエクセルの
変数の設定
エクセルが立ち上がっていなければ
エクセルを立ち上げる。
二つの円の座標の初期値
エクセルの実体化
ブックの生成
シートの設定
円1の形
円2の形
円の色
プログラムで、例外が起きたら、
ブックを閉じ、エクセルを
終了させる。
タイマーのスタート
インターバルは
それぞれのタイマーのプロパティ
で、それぞれ設定しする。
タイマー1の動作
タイマー2の動作
ボタン2で、タイマーのストップと
エクセルアプリケーション
の終了。
|