| 
    
     |  | 皆さん、こんばんは。 
 >>Application.OnTime Now + TimeValue("00:00:5"), "あ"
 >の前後のプログラムも提示してください。
 同感です。
 難しい内容なのに質問の記述があやふやな箇所がちょっと多いですね!!
 
 Ontimeの問題ではなく、何かが非同期に作動している
 "あ"というプロシジャーの中の作り方の問題ではないのですか?
 
 
 例えば、「IEを起動して適当なHPを表示し、完全に表示されたら
 IEを閉じる」という動作を1秒毎に8回繰り返す
 
 なんていう仕様を考えます。
 
 新規ブックで
 
 「Microsoft Internet Controls」に参照設定をした状態で
 
 Thisworkbookモジュールに
 '================================================
 Public WithEvents ie As InternetExplorer
 Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
 ie.Quit
 Set ie = Nothing
 End Sub
 
 
 標準モジュールに
 '==============================================================
 Private cnt As Long
 Sub test1()
 If cnt >= 8 Then cnt = 0
 With ThisWorkbook
 Set .ie = CreateObject("InternetExplorer.Application")
 With .ie
 .Visible = True
 .Navigate "http://www.vbalab.net/vbaqa/c-board.cgi?id=excel"
 End With
 End With
 cnt = cnt + 1
 If cnt < 8 Then Application.OnTime Now() + TimeValue("00:00:01"), "test1"
 End Sub
 
 でtest1を実行すると、
 一回だけなら成功しますが、上記のようなコードですと
 同期が取れていないのでいくつもIEが立ち上がってしまいます。
 
 
 これを
 Thisworkbookには、
 '==================================
 Public WithEvents ie As InternetExplorer
 Public ie_comp As Boolean
 Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
 ie_comp = True
 End Sub
 
 
 標準モジュールに
 '==========================================================
 Private cnt As Long
 Sub test2()
 On Error Resume Next
 If cnt >= 8 Then cnt = 0
 With ThisWorkbook
 .ie_comp = False
 Set .ie = CreateObject("InternetExplorer.Application")
 With .ie
 .Visible = True
 .Navigate "http://www.vbalab.net/vbaqa/c-board.cgi?id=excel"
 End With
 Do While .ie_comp = False
 DoEvents
 Loop
 .ie.Quit
 Set .ie = Nothing
 End With
 cnt = cnt + 1
 If cnt < 8 Then Application.OnTime Now() + TimeValue("00:00:01"), "test2"
 End Sub
 
 とすると、IEとtest2で同期が取られるので
 いくつもIEが起動しません。
 
 内容は違いますが(違うのは当たり前ですけど)、こういう現象ではないのですか?
 だとしたら、同期を取る方法を考えないとなりませんね!!
 
 |  |