この記事では、指定した時間までマクロを一時停止させる方法について説明しています。Application.Wait
メソッドを使用し、指定された時間が来るとTrueを返します。このメソッドはExcelの全活動を停止させるため、他の作業を行うことができなくなりますが、印刷や再計算などのバックグラウンドプロセスは続行されます。具体例として、特定の時間まで待機する方法や、約10秒待機する方法が示されています。サポートやフィードバックについての情報も提供されています。
Excel VBAのWaitメソッドについて
Excel VBAでは、マクロを特定の時間まで一時停止するために使用されるメソッドがあります。このメソッドは、指定時間が到達すると、Trueを返します。この記事では、Waitメソッドの使い方を詳しく説明します。
構文
expression.Wait(Time)
- expression: Applicationオブジェクトを表す変数です。
パラメーター
名前 | 必須/オプション | データ型 | 説明 |
---|---|---|---|
Time | 必須 | Variant | マクロを再開させたい時間で、Microsoft Excelの日付形式で指定します。 |
戻り値
- Boolean
注意事項
Waitメソッドは、Excelのすべてのアクティビティを一時停止させ、その間に他の操作を行うことができない場合があります。しかし、印刷や再計算などのバックグラウンド処理は継続されます。
例
例1: 指定した時刻までマクロを一時停止
以下のコードは、今日の午後6時23分までマクロを一時停止します。
Application.Wait "18:23:00"
例2: 約10秒間の一時停止
次の例は、実行中のマクロを約10秒間一時停止させます。
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
例3: 10秒が経過したかどうかを示すメッセージを表示
以下のコードは、10秒間の一時停止が経過したかを確認し、メッセージを表示します。
If Application.Wait(Now + TimeValue("0:00:10")) Then
MsgBox "Time expired"
End If
サポートとフィードバック
Office VBAやこのドキュメントに関して質問やフィードバックがある場合は、Office VBAサポートとフィードバックをご覧ください。サポートを受ける方法やフィードバックの提供方法についてのガイダンスが得られます。
このように、Waitメソッドを利用することで、特定の時刻までマクロを一時停止させることができ、自動化されたタスクの管理がさらに便利になります。
————-
Application.Wait method (Excel) | Microsoft Learn
Source link
The article discusses the Wait
method in Microsoft Excel VBA, which pauses a running macro until a specified time. The syntax for the method is expression.Wait(Time)
, where expression
represents an Application object, and Time
is a required parameter indicating the time for the macro to resume, formatted in Excel date format. The method returns a Boolean value: it returns True
if the specified time has arrived.
Key points include:
- The
Wait
method halts all Excel activity, potentially preventing other operations while in effect, although some background processes like printing and recalculation will continue. - Examples demonstrate how to pause a macro until a specific time (e.g., 6:23 PM) and how to pause it for approximately 10 seconds. Additionally, there’s an example that displays a message box when the 10 seconds have elapsed.
The article also encourages readers to seek support or feedback regarding Office VBA and provides guidance on how to do so.
コメント