投稿日 | : 2004/02/04(Wed) 17:37 |
投稿者 | : ak |
Eメール | : |
URL | : |
タイトル | : タイマー無しで |
タイマーを使う必要が無いような気がします。
という事でタイマー無しのサンプルを下記に記述しておきます。
'(*.frm)フォームにCommandButtonとLabelをそれぞれ1つ配置してください。
Option Explicit
Private pbRunFlg As Boolean
Private Sub Form_Load()
pbRunFlg = False
End Sub
Private Sub psbData()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim iRow As Integer
Dim iCnt As Integer
Dim tm
pbRunFlg = True
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add
xlApp.Visible = True
Do
DoEvents
iCnt = iCnt + 1
iRow = 9 + iCnt
xlSheet.Cells(iRow, 10) = iCnt
Label1.Caption = iCnt
Call psbWait(1000)
If iCnt = 32767 Or Not pbRunFlg Then Exit Do
tm = Timer
Do While Not tm + 1 <= Timer '1秒間処理を止める
DoEvents
Loop
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
Private Sub Command1_Click()
If pbRunFlg Then
pbRunFlg = False
Else
Call psbData
End If
End Sub