VBA auto hide ribbon in Excel 2013 - vba

How to Auto-hide Ribbon in Excel 2013 in VBA? I would like to achieve exactly what I get by clicking on the upper arrow icon at the right top of Excel menu marked with blue in the picture below and then clicking on the first option marked with orange:
I would be also interested in VBA switching back to the third option Show Tabs and Commands. Important thing for me is to keep in the Excel menu the upper arrow icon (marked with blue).
I have tried hints shown in this thread: VBA minimize ribbon in Excel
but I am not satisfied with results.
Attempt 1
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)
This is good but hides the blue icon.
Attempt 2
CommandBars.ExecuteMso "MinimizeRibbon"
This is close to what I want. This keeps the blue icon but does not hide the entire menu. It switches to the second option displayed in the picture Show Tabs.
Attempt 3
SendKeys "^{F1}"
The attampt does not work at all. Moreover, it is supposed to imitate the attempt 2. So even that would not satisfy me.

I can't see that anyone else has brought this up... This isn't a workaround, this is the actual idMSO for what I think you're looking for. This code makes my excel window look like everything is gone the same way the first option does for Auto-Hide Ribbon.
Before the code runs, my window looks like this, in the 'Restore' size:
Running the following code:
Sub HideTheRibbon()
CommandBars.ExecuteMso "HideRibbon"
End Sub
Will make your window look like this, in the maxamized window size (just like what would happen if you were to press the Auto-Hide Ribbon button manually):
If you want the ribbon automatically hidden when the workbook opens, put this in the workbook code:
Sub Workbook_Open()
CommandBars.ExecuteMso "HideRibbon"
End Sub
Alternatively, to achieve the same thing, you could put this code in a module:
Sub Auto_Open()
CommandBars.ExecuteMso "HideRibbon"
End Sub
If you want the window to revert back to normal, you run the exact same code again. In other words, the following code would make no visual change at all when ran because the idMSO "HideRibbon" is a toggleButton:
Sub HideTheRibbon()
CommandBars.ExecuteMso "HideRibbon"
CommandBars.ExecuteMso "HideRibbon"
End Sub
If you want a full list of all the idMSO in excel, click the following that apply to you: Excel 2013+, Excel 2010, Excel 2007

I use this for presentation purposes
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayHeadings = False
Application.DisplayFormulaBar = False
Application.DisplayFullScreen = True This is what i used to hide the ribbon

Probably you should do something a little more complicated:
Use CommandBars.ExecuteMso "MinimizeRibbon" to show/hide the ribbon.
Depending on what you want, you may show/hide all other tabs in the ribbon. E.g. use something of the code here -> Excel Hide/Show all tabs on Ribbon except custom tab
Thus 2 steps:
Step 1 - show or hide with the CommandBars.ExecuteMso
Step 2 - show or hide the rest of the tabs with some macros from the link.
A little big workaround, but you will get what you want.

I call this macro on Workbook_Open to check for the ribbon and if not hidden, it will hide the ribbon (I actually have it located in another Sub that also removes the formula bar, status bar, headings, and gridlines at Workbook_Open)...
Sub HideRibbon()
If CommandBars("Ribbon").Controls(1).Height < 100 Then
Exit Sub
Else
CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub
Then I call this macro on Workbook_BeforeClose to check for the ribbon and if it is not shown, it will show the ribbon for the next excel spreadsheet that is opened.
Sub ShowRibbon()
If CommandBars("Ribbon").Controls(1).Height > 100 Then
Exit Sub
Else
CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub
This eliminates the chance of hiding the ribbon when the workbook is opened and a user then manually showing the ribbon which in turn would reverse the show on close and actually hide the ribbon. On open, the ribbon would then be shown again. This will keep it the same every time on open and close of the workbook.

Give this a try:
Sub ShowHideRibbon()
If CommandBars("Ribbon").Controls(1).Height < 100 Then
CommandBars.ExecuteMso ("MinimizeRibbon")
Else
CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub
Or this:
Sub ShowHideRibbon1()
If Application.ExecuteExcel4Macro("Get.ToolBar(7,""Ribbon"")") Then
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)"
Else
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", True)"
End If
End Sub

First, go to the Excel Options, and go to "Quick Action Toolbar".
From there, search for "Hide Ribbon" and add to the toolbar. After it's on the QAT, you can call it quickly with ALT+# (on my computer it's the 8th thing, so ALT+8 will auto-hide).
Then just add a sub that does SendKeys ALT then 8:
Sub Macro1()
ActiveSheet.Activate
'Cells(1, 1).Select
SendKeys "%0", True
SendKeys "8", True
End Sub
Note: I know it's silly to have ActiveSheet.Activate, I just added that to test the macro. Depending on how it's being called, you can remove/comment out that line. The % is equivalent to ALT, and technically, I have to press 0 then 8, hence the two lines.

To get this code to work in excel 2016 you will need the following code in the "ThisWorkbook" mode.
Credit goes to BigBen - not me
Private Sub Workbook_Open()
application.CommandBars.ExecuteMso "HideRibbon"
End Sub

Related

How to run the VBA code while selecting an drop down menu item

In my MS Word form, there are some drop down menus. By default "Yes" is the green and "No" is the red in color while the file is opened. I would like to change the font color of the drop down menu items while selected, to be Red in case of "No" and to be Green in case of "Yes".
For this purpose I have created a Document_ContentControlOnExitsub currently only for the "Did the AA's performance drop after the incident? question in the following MS Word form. But the code is not running while selecting the "Yes" from the drop down menu. I can write and run VBA code in MS Excel but new to MS Word VBA, thus confused how to run the code. Can any one help?
I also would like to create a VBA code which will check and make sure that all "No" are Red and "Yes" are Green while the file is opened. So I think, there should be a VBA which will run during the MS Word file opening and iterate through all the Drop Down menus for that purposes. But this is secondary, if solved, bonus but not so important, at this moment it is important to me to change the font color during selecting menu items.
Here is the VBA code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
If .Title = "incident" Then
Select Case .Range.Text
Case "Yes": .Range.Font.ColorIndex = wdRed
Case "No": .Range.Font.ColorIndex = wdBrightGreen
Case Else: .Range.Font.ColorIndex = wdAuto
End Select
End If
End With
End Sub
Here is the MS Word file:
https://drive.google.com/file/d/1Avjx8nubEIp9K9NwqtyfHvdohQEsQiP8/view?usp=sharing
Check which module your code is in.
Document_ContentControlOnExit is a document level event handler so it should be in the "ThisDocument" module.
Also note that in the tools area at the top of that module there are two drop down menus. These can be used to create event handlers for the document's objects and are useful to ensure that the syntax is correct.

Presenter-only pop-up in Powerpoint

Is it possible to show a pop-up message (using VBA in Powerpoint) to the presenter which won't be visible to the "audience"?
Edit: Of course, it would be nice if you could tell me "how".
Thanks in advance!
Something like this, perhaps:
Add a userform with a label to contain the text you want to display.
Add this to the vba project:
Sub PopUp()
With UserForm1
.Show (vbModeless)
.Left = 100
End With
End Sub
Add a shape to any slide where you want to display the popup and give it an action setting of Run Macro: PopUp
This assumes that you've accepted the default userform name; change the subroutine to reflect any name changes if you like.
It also assumes that the main monitor is on the left side; if not, you'll need to change the .Left value.

Invoking the Activate dialog for sheets

I want to invoke the Activate dialog for sheets in a workbook such as below. This dialog can be called manually by right clicking on the arrow button at the bottom left of Excel (2013).
I tried this:
Application.Dialogs(xlDialogActivate).Show
But instead of showing the list of sheets, it shows the list of open workbooks:
How do I call the Activate dialog for sheets?
You could create your own dialog box if you want. Create a userForm and populate it with the names of the Worksheets upon activation. You can see what the user selected through the selected function, e.g.
ListBox1.Selected(i)
You can then call a sub with the name of the Sheet and activate it, e.g.
Sub ChangeSheet(SheetName)
Worksheets(SheetName).Activate
End Sub
An alternative is to show the Sheet Command bar:
Sub ShowSheets()
Application.CommandBars("Workbook tabs").ShowPopup
End Sub
Content salvaged from comments by Scott Holtzman and Davesexcel.

Execute VBA from Excel 2010 Ribbon

I have been trying different examples of how to move my VBA buttons into the ribbon but either I the text is flagging red(aka error) or examples relate to doing some xml conversions (never done before so they make no sense).
All I want to do is move my text coloring buttons into my custom ribbon. When the user clicks on the button icon(inside the Ribbon), the VBA coding executes.
As you can see above, currently the Text-Green button on the ribbon...
when the user clicks it.. it generates a blank Command Button for User to create new Command Buttons. Clearly not what I want.
Any suggestions?
My Blue and Red button coding (simple coding):
Private Sub Color_Blue_Click()
Selection.Font.Color = RGB(83, 141, 213)
End Sub
Private Sub Color_Red_Click()
Selection.Font.Color = RGB(255, 0, 0)
End Sub
I have tried referencing:
http://www.rondebruin.nl/win/section2.htm
Wow I guess it was a simple fix afterall:
I went to:
Developer Tab/Record Macro
Named the Macro as TextGreen.... clicked Ok and once it was saved I clicked Stop Recording
Went back to Developer/Code Tab and clicked on Macros
Then I clicked Edit and typed my code there:
Sub TextGreen()
Selection.Font.Color = RGB(0, 176, 80)
End Sub
To save to ribbon I did:
Right click Ribbon/Customize Ribbon... Selected Macros from drop down...saved a group under my Ribbon Tab and Added it.

Macro enabled button VBA

I'm working with VBA macros and I have a macro enabled button of which I want to disable from being clicked when the workbook is first opened. Is there anyway to do this. The macro behind it just leads to another worksheet. ![enter image description here][1]
Any help would be great
Thanks
If your button is an ActiveX Command Button, put the following code in ThisWorkbook:
Private Sub Workbook_Open()
Worksheets("Sheet1").OLEObjects("CommandButton1").Enabled = False
End Sub
Change "Sheet1" to reference the sheet that contains the button and change "CommandButton1" to reference the name of the button.