VBA在Excel 2013中自动隐藏功能区 [英] VBA auto hide ribbon in Excel 2013

查看:683
本文介绍了VBA在Excel 2013中自动隐藏功能区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在VBA的Excel 2013中Auto-hide Ribbon?我想通过单击下面图片中标有蓝色的Excel菜单右上角的上箭头图标,然后单击标有橙色的第一个选项,来实现我所得到的确切结果:

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:

我也会对VBA切换回第三个选项Show Tabs and Commands感兴趣.对我来说重要的是,请在Excel菜单中保留上方的箭头图标(标有蓝色).

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).

我尝试了此线程中显示的提示: VBA在Excel中最小化功能区 但我对结果不满意.

I have tried hints shown in this thread: VBA minimize ribbon in Excel but I am not satisfied with results.

尝试1

Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)

这很好,但隐藏了蓝色图标.

This is good but hides the blue icon.

尝试2

CommandBars.ExecuteMso "MinimizeRibbon"

这接近我想要的.这将保留蓝色图标,但不会隐藏整个菜单.它将切换到图片Show Tabs中显示的第二个选项.

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.

尝试3

SendKeys "^{F1}"

该附件根本不起作用.而且,它应该模仿尝试2.因此,即使那样也不能令我满意.

The attampt does not work at all. Moreover, it is supposed to imitate the attempt 2. So even that would not satisfy me.

推荐答案

我看不到有人提出了这个建议……这不是解决方法,这是我认为您真正的idMSO重新寻找.这段代码使我的excel窗口看起来像第一个选项Auto-Hide Ribbon一样都消失了.

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.

在代码运行之前,恢复"大小的窗口如下所示:

运行以下代码:

Sub HideTheRibbon()
    CommandBars.ExecuteMso "HideRibbon"
End Sub

将以最大化的窗口大小使窗口看起来像这样(就像您手动按Auto-Hide Ribbon按钮时会发生的情况一样):

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):

如果要在打开工作簿时自动隐藏功能区,请将其放入工作簿代码中:

Sub Workbook_Open()
    CommandBars.ExecuteMso "HideRibbon"
End Sub

或者,要实现相同的目的,可以将以下代码放在模块中:

Sub Auto_Open()
    CommandBars.ExecuteMso "HideRibbon"
End Sub

如果希望窗口恢复为正常状态,请再次运行完全相同的代码.换句话说,由于idMSO"HideRibbon 是一个toggleButton:

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

如果要获取excel中所有idMSO的完整列表,请单击以下适用于您的内容: Excel 2010 Excel 2007

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

这篇关于VBA在Excel 2013中自动隐藏功能区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆