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 1 year has passed since last update.

AccessのVBAでAccessのウィンドウを最前面に移動

Posted at

概要

AccessでSeleniumBasicを使ってChromeの自動処理してる。

自動処理終わったらChromeのウィンドウを残しつつ、Accessでダイアログ(終了通知)出したい。

でもAccessのウィンドウがChromeの後ろに隠れている状態になるで、Accessのダイアログが見えない。
(ダイアログ出したからといってAccessのウィンドウが最前面に来るわけではない)

Accessのウィンドウを最前面に移動させたい。

やり方

user32に SetForegroundWindow という関数がある。
それを使うとウィンドウを最前面に移動できる。
Accessのウィンドウハンドルが必要だが、それは Me.hwnd で取得できる。

サンプルコード
'ウィンドウ操作はuser32.dllの力を借りる。
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


'Sub終わった後もChromeのウィンドウを残しておきたいので、この位置で変数宣言。
Dim WEB_DRIVER_ As Selenium.WebDriver


Private Sub tester_Click()
    
    
    Set WEB_DRIVER_ = New Selenium.WebDriver
    
    'Chrome起動。(Accessのウィンドウは後ろに隠れてしまう)
    Call WEB_DRIVER_.Start("chrome")
    
    'Chromeでなんかいろいろ自動処理。
    
    'Accessのウィンドウを最前面に持ってくる。
    SetForegroundWindow Me.hwnd
    
    'ダイアログ出す。
    MsgBox "花京院 イギー アヴドゥル 終わったよ", vbInformation
    

End Sub

バージョン

Windows 10 Pro 22H2 OSビルド 19045.2546
Microsoft Access for Microsoft 365 MSO (バージョン 2212 ビルド 16.0.15928.20196) 32 ビット

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?