0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Access VBA】kernel32.dllを用いてSleepをモジュールで使用できるようにする。

Posted at

自分用のメモとして残します。

普段はwebエンジニアなので、久しぶりに使用しようとしたときに面倒だったのでメモします。

やり方

1.kernel32を宣言

モジュールの一番上に下記を追記↓

# If VBA7 Then
    #64bitのoffice用
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As Long)
# Else
    #32bitのoffice用
    Private Declare Sub Sleep Lib "kernel32" (ByVal ms As Long)
# End If

2.Sleepを任意の箇所で呼び出す

同モジュール内で呼び出す。

Function hoge()
    #ミリ秒
    Sleep 5000 

End Function

SleepのリファレンスURL
https://docs.microsoft.com/ja-jp/windows/win32/api/synchapi/nf-synchapi-sleep

以上です。

余談

kernel32に限ったことではありませんが、コアとなるライブラリで何が使えるのか一通り目を通しておいた方が、貧弱VBAくんの手助けにもなるかもですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?