AW: Excel nicht über das rote X beenden
05.01.2007 19:15:32
Ramses
Hallo
Das EXCEL-Systemmenü global abzusetzen geht meines Wissens nach nicht.
Aber du kannst das Arbeitsmappenbezogen herstellen
Probier mal.
Der ganze Code in ein Modul deiner Arbeitsmappe
Option Explicit
'Begin der Funktion
Public Const GWL_STYLE = (-16)
Public Const WS_SYSMENU = &H80000
'---
Declare
Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare
Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare
Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare
Function DrawMenuBar Lib "User32" (ByVal hWnd As Long) As Long
Sub Hide_SYSMENU()
Dim xl_hwnd, lStyle
xl_hwnd = FindWindow("xlmain", vbNullString)
If xl_hwnd <> 0 Then
lStyle = GetWindowLong(xl_hwnd, GWL_STYLE)
lStyle = SetWindowLong(xl_hwnd, GWL_STYLE, lStyle And Not WS_SYSMENU)
DrawMenuBar xl_hwnd
End If
End Sub
Sub Show_SYSMENU()
Dim xl_hwnd, lStyle
xl_hwnd = FindWindow("xlmain", vbNullString)
If xl_hwnd <> 0 Then
lStyle = GetWindowLong(xl_hwnd, GWL_STYLE)
lStyle = SetWindowLong(xl_hwnd, GWL_STYLE, lStyle Or WS_SYSMENU)
DrawMenuBar xl_hwnd
End If
End Sub
Aus dem Workbook_Open Ereignis das "Hide_SYSMENU" aufrufen, und im Workbook_BeforeClose Ereignis das Show_SYSMENU aufrufen.
Gruss Rainer