Professional Documents
Culture Documents
123
123
' This variable is initalized in the UserForm_Initialize() event. It holds the hWnd
to the Excel Application Window.
Global xlHwnd As LongPtr
' This API call is used to hide or show the Excel Application.
Public Declare PtrSafe Function ShowWindow _
Lib "user32.dll" _
(ByVal hwnd As LongPtr, _
ByVal nCmdShow As Long) _
As Long
' Returns the Window Handle of the Window that is accepting User input.
Private Declare PtrSafe Function GetForegroundWindow Lib "user32.dll" () As LongPtr
Sub KeepFormOnTop()
ret = ShowWindow(xlHwnd, 0)
ret = SetWindowPos(GetForegroundWindow(), HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE + SWP_NOSIZE)
End Sub
Call Keep_Form_On_Top_64bit.KeepFormOnTop
End Sub
Private Sub UserForm_Initialize()
Keep_Form_On_Top.xlHwnd = Excel.Application.hwnd
End Sub