VBA-Programmierung in Microsoft Excel

Tutorial: Excel-Beispiele

Excel-Menü oben links am Fenster ausblenden

Gruppe

API

Bereich

Menue

Thema

Excel-Menü oben links am Fenster ausblenden

Problem

Wie kann ich das Excel-Menü oben links im Fenster ausblenden und im DATEI-Menü die BEENDEN-Schaltfläche deaktivieren?

Lösung

Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.




StandardModule: basMain

Declare Function FindWindowA Lib "User32" _
   (ByVal lpClassName As Any, _
   ByVal lpWindowName As String) As Long
Declare Function GetWindowLongA Lib "User32" _
   (ByVal hwnd As Long, ByVal nIndex As Integer) As Long
Declare Function SetWindowLongA Lib "User32" _
   (ByVal hwnd As Long, ByVal nIndex As Integer, _
   ByVal dwNewLong As Long) As Long

Global Const GWL_STYLE = (-16)
Global Const WS_SYSMENU = &H80000

Sub RemoveControlMenuExcel32()
   Dim WindowStyle As Long
   Dim hwnd As Long
   Dim WindowName As String
   Dim result
   WindowName = Application.Caption
   hwnd = FindWindowA(0&, WindowName)
   WindowStyle = GetWindowLongA(hwnd, GWL_STYLE)
   WindowStyle = WindowStyle And (Not WS_SYSMENU)
   result = SetWindowLongA(hwnd, GWL_STYLE, WindowStyle)
End Sub

Sub RestoreControlMenuExcel32()
   Dim WindowStyle As Long
   Dim hwnd As Long
   Dim WindowName As String
   Dim result
   WindowName = Application.Caption
   hwnd = FindWindowA(0&, ByVal WindowName)
   WindowStyle = GetWindowLongA(hwnd, GWL_STYLE)
   WindowStyle = WindowStyle Or WS_SYSMENU
   result = SetWindowLongA(hwnd, GWL_STYLE, WindowStyle)
End Sub

Sub SetEnabledTrue()
   Application.CommandBars("Worksheet Menu Bar"). _
      Controls("Datei").Controls("Beenden").Enabled = True
   Call RestoreControlMenuExcel32
End Sub

Sub SetEnabledFalse()
   Application.CommandBars("Worksheet Menu Bar"). _
      Controls("Datei").Controls("Beenden").Enabled = False
   Call RemoveControlMenuExcel32
End Sub

    


Beiträge aus dem Excel-Forum zu den Themen API und Menue