Как скрыть панели инструментов Excel 2003 и ленту Excel 2007 при помощи макроса на VBA
Чтобы убрать с экрана все лишние элементы интерфейса Excel, можно выспользоваться таким кодом:
(скрываются все панели инструментов в Excel 2003 и лента в Excel 2007; скрываются ярлычки листов, линейки и полосы прокрутки; изменяется название окна приложения)
При необходимости можно отображать нужную панели инструментов, в то время, как остальные панели будут скрыты)
Private Sub ChangeInterface(Value As Boolean) With Application .ScreenUpdating = False .Caption = IIf(Value = True, Empty, "Наше окно") .DisplayStatusBar = Value: .DisplayFormulaBar = Value Dim iCommandBar As CommandBar For Each iCommandBar In .CommandBars iCommandBar.Enabled = Value Next With .ActiveWindow .Caption = IIf(Value = True, .Parent.Name, "") .DisplayHeadings = Value: .DisplayGridlines = Value .DisplayHorizontalScrollBar = Value: .DisplayVerticalScrollBar = Value .DisplayWorkbookTabs = Value End With .ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", " & Value & ")" .ScreenUpdating = True End With End Sub Private Sub УбратьВсё() ChangeInterface False End Sub Private Sub ВосстановитьИнтерфейс() ChangeInterface True End Sub
Чтобы скрывать панели инструментов Excel 2003 и ленту Excel 2007 только для одной книги,
поместите в модуль ЭтаКнига следующий код:
(при переключении на другой файл интерфейс Excel будет восстанавливаться)
Private Sub Workbook_Open() ' открытие книги УбратьВсё End Sub Private Sub Workbook_Activate() ' возврат на эту книгу из другой УбратьВсё End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) ' закрытие книги ВосстановитьИнтерфейс End Sub Private Sub Workbook_Deactivate() ' переключение на другую книгу ВосстановитьИнтерфейс End Sub
См. пример в прикреплённом файле:
- 39157 просмотров
Не получается применить макрос? Не удаётся изменить код под свои нужды?
Оформите заказ у нас на сайте, не забыв прикрепить примеры файлов, и описать, что и как должно работать.
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
How can I hide and show all the standard Excel ribbon tabs using VBA (not XML)
The answer is «YOU CAN’T«.
AFAIK, you can’t do that using VBA. Unfortunately VBA doesn’t expose the tabs. The only options that you have are as shown in the image below
So you can work with the commandbar, commandbarButton, commandbarComboBox etc…
You can say that Set cbar = Application.CommandBars("Ribbon") but after that, the problem that you will face is how to get a handle for the tabs.
What you can do with the Ribbon using VBA:
- Determine whether a particular control is Enabled/Visible/Pressed(Toggleboxes/CheckBoxes)
- Get a control’s label, screen tip, or supertip Display the image associated with a
control. - Execute a particular control.
What you can’t do with the Ribbon using VBA:
- Determine which tab is currently selected.
- Activate a particular tab.
- Hide a particular tab
- Add a new tab.
- Add a new group to a tab.
- Add a new control.
- Remove/Disable/Hide a control.
You can however use XML to achieve what you want. For example
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabReview" visible="false" />
</tabs>
</ribbon>
</customUI>
But I guess you do not want to go via the XML Route.



