AW: Ungebundene Userform immer im vordergrund
18.06.2008 00:33:27
Johannes
Hallo Stefan,
Quelle: Nepumuk @office-loesung.de ... und fuer gut befunden. :-)
Option Explicit
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "User32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Enum SWP_Flags
SWP_NOSIZE = &H1
SWP_NOMOVE = &H2
SWP_NOACTIVATE = &H10
SWP_SHOWWINDOW = &H40
End Enum
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Sub UserForm_Activate()
Call prcSetForeground
End Sub
Private Sub prcSetForeground()
SetWindowPos GetHandle, HWND_TOPMOST, 0&, 0&, 0&, 0&, _
SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
Private Sub prcSetBackground()
SetWindowPos GetHandle, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, _
SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
Private Function GetHandle() As Long
Select Case Val(Application.Version)
Case 8 'Office 97
GetHandle = FindWindow("ThunderXFrame", Me.Caption)
Case Else 'ab Office 2000
GetHandle = FindWindow("ThunderDFrame", Me.Caption)
End Select
End Function