Excel auto-hide ribbon difference between "manual way" and vba code

Das443344

New Member
Joined
Mar 12, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I need to have my Excel file with the ribbon hidden.
I have what I need if I do it manully with the button "auto-hide ribbon " from the "ribbon display option":
1606839450326.png


If i do it with vba code I don't have the same result:
1606839543920.png


as you can see, with the vba code Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)", the top and bottom bars are different. So the vba code is not doing what you can do manually.

I don't understand how to do in vba to obtein the same result as if I do it manually.

I hope is clear :)

thank you for your support!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
See if this works for you :

In a Standard Module:
VBA Code:
Option Explicit

#If VBA7 Then
    #If Win64 Then
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongLong, ByVal nIndex As Long) As LongLong
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongLong, ByVal nIndex As Long, ByVal dwNewLong As LongLong) As LongLong
    #Else
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    #End If
#Else
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If


Public Property Let HideRibbon(Optional ByVal bHideExcelCaption As Boolean, ByVal bHide As Boolean)

    Const GWL_STYLE = (-16)
    Const WS_CAPTION = &HC00000
    
    #If Win64 Then
        Dim lStyle As LongLong
    #Else
        Dim lStyle As Long
    #End If

    Call Application.ExecuteExcel4Macro("show.toolbar(""Ribbon"",Not(" & bHide & "))")
    
    lStyle = GetWindowLong(Application.hwnd, GWL_STYLE)
    If bHide Then
        If bHideExcelCaption Then
            lStyle = lStyle And Not WS_CAPTION
        End If
    Else
        lStyle = lStyle Or WS_CAPTION
    End If
    Call SetWindowLong(Application.hwnd, GWL_STYLE, lStyle)

End Property

Code Usage to toggle the ribbon + caption visibility :
VBA Code:
Sub Hide_Ribbon()
    HideRibbon(bHideExcelCaption:=True) = True
End Sub

Sub Show_Ribbon()
    HideRibbon = False
End Sub
 
Upvote 0
Thank you for the answer, however is still not the result I was expecting, as you can see, the bottom bar is still present:
1606920991388.png


you can see the "ready" text and zoom buttons with 100%.
is not like when you do manually the auto-hide ribbon button.

thank you!
 
Upvote 0
To show/hide status bar use Application.DisplayStatusBar = True ' or = False
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top