AW: Oberes Banner ausblenden
15.01.2026 14:30:50
volti
Hallo Jörg,
hast Du einen speziellen Grund, weshalb Du für jede Aktion eine eigene Sub verwendest?
Das Ausschalten der Titelleiste (Caption) hängt hier bei Excel auch mit dem Status der Menueleiste usw. zusammen, daher sind zwei Extra-Subs hierfür m.E. nicht empfehlenswert.
Ich habe Dir im u.a. Code daher alles in eine Sub AusEin1 gepackt, die sowohl das Ein- wie auch das Ausschalten anhand des übergebenen Werts handelt.
Hier wird zum Menübandausschalten das bereits empfohlene ExecuteExcel4Macro, ein immer noch funktionierendes Relikt aus Zeiten vor Excel5, verwendet.
In der Sub AusEin2 habe ich anstelle dessen alternativ den Befehl DisplayFullScreen verwendet.
Option Explicit
Private Declare PtrSafe Function GetWindowRect Lib "user32" ( _
ByVal hWnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function SetWindowPos Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal hWndInsertAfter As LongPtr, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongA Lib "user32" Alias "GetWindowLongPtrA" ( _
ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongA Lib "user32" Alias "SetWindowLongPtrA" ( _
ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongA Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongA Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const GWL_STYLE As Long = (-16)
Private Const SWP_MYSTYLE As Long = &H224 ' SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOREPOSITION
Private Const WS_MYSTYLE As Long = &HCB0000 ' WS_CAPTION + WS_SYSMENU + WS_MAXIMINIMIZEBOX
Private Sub AusEin1(ByVal bWie As Boolean)
Dim hStil As LongPtr, R As RECT
With Application
GetWindowRect .hWnd, R
If bWie Then
.ExecuteExcel4Macro "Show.Toolbar(""Ribbon"", true)"
Else
.ExecuteExcel4Macro "Show.Toolbar(""Ribbon"", false)"
End If
.DisplayStatusBar = bWie ' Statusbar ein/aus
.DisplayFormulaBar = bWie ' Eingabefeld ein/aus
With ActiveWindow
.DisplayWorkbookTabs = bWie ' Register ein/aus
.DisplayHeadings = bWie ' Zeilen/Spaltenbezeichnungen ein/aus
.DisplayHorizontalScrollBar = bWie ' Scrollleiste ein/aus
.DisplayVerticalScrollBar = bWie ' Scrollleiste ein/aus
End With
hStil = GetWindowLongA(.hWnd, GWL_STYLE)
SetWindowLongA .hWnd, GWL_STYLE, IIf(bWie, hStil Or WS_MYSTYLE, hStil And Not WS_MYSTYLE)
SetWindowPos .hWnd, 0, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, SWP_MYSTYLE
End With
End Sub
Public Sub Aus()
Call AusEin1(False)
End Sub
Public Sub Ein()
Call AusEin1(True)
End Sub
Private Sub AusEin2(ByVal bWie As Boolean)
' Alternative mit gleichen Funktionen
Dim hStil As LongPtr, R As RECT
With Application
GetWindowRect .hWnd, R
.DisplayFullScreen = Not bWie ' Vollbild ein/aus
.DisplayStatusBar = bWie ' Statusbar ein/aus
.DisplayFormulaBar = bWie ' Eingabefeld ein/aus
With ActiveWindow
.DisplayWorkbookTabs = bWie ' Register ein/aus
.DisplayHeadings = bWie ' Zeilen/Spaltenbezeichnungen ein/aus
.DisplayHorizontalScrollBar = bWie ' Scrollleiste ein/aus
.DisplayVerticalScrollBar = bWie ' Scrollleiste ein/aus
End With
hStil = GetWindowLongA(.hWnd, GWL_STYLE)
SetWindowLongA .hWnd, GWL_STYLE, IIf(bWie, hStil Or WS_MYSTYLE, hStil And Not WS_MYSTYLE)
SetWindowPos .hWnd, 0, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, SWP_MYSTYLE
End With
End Sub
Gruß
KH