Hallo,
ich habe ein Problem mit meiner MsgBox. Das Positionieren passt, jedoch JA Nein funktioniert nicht.
Danke!
Gruß Sigi
Sub Aufruf_MsgBox()
If msg("Möchten Sie die " & vbNewLine & _
"Tabelle verlassen " & vbNewLine & _
"verlassen… " _
, vbYesNo + vbCritical, „Tabelle 1 verlassen…“, 0, 0) Then
If vbNo = True Then
Sheets(„Tabelle2“).Select
ElseIf vbYes = True Then
Exit Sub
End If
End If
End Sub
Private Declare Function FindWindow Lib „user32“ Alias _
„FindWindowA“ (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Public Declare Function UnhookWindowsHookEx Lib „user32“ (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib „user32“ Alias „GetWindowLongA“ (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib „kernel32“ () As Long
Public Declare Function SetWindowsHookEx Lib „user32“ Alias „SetWindowsHookExA“ (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public 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
Public Declare Function GetWindowRect Lib „user32“ (ByVal hwnd As Long, lpRect As RECT) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
Public hHook As Long
Public MsgBoxPosX As Integer
Public MsgBoxPosY As Integer
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetWindowPos wParam, 0, MsgBoxPosX, MsgBoxPosY, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
UnhookWindowsHookEx hHook
End If
WinProc = False
End Function
Function msg(msgText As String, msgButton As Long, msgTitel As String, ByVal xPos As Long, ByVal yPos As Long)
Dim hInst As Long
Dim XLInst As Long
Dim Thread As Long
MsgBoxPosX = xPos
MsgBoxPosY = yPos
XLInst = FindWindow(„xlmain“, vbNullString)
hInst = GetWindowLong(XLInst, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, hInst, Thread)
MsgBox msgText, msgButton, msgTitel, 0, 0
End Function