使用 VBA 最小化 Office 功能区?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2640986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:33:10  来源:igfitidea点击:

Minimize the Office Ribbon with VBA?

ms-accessvbaribbon

提问by Icode4food

I haven't searched real hard recently but in the past I have searched high and low to figure out a way to minimize the ribbon with VBA code. For me, most of my users have no use for the ribbon in Access, I would be very happy if I could reclaim the screen real estate for them.

我最近没有真正努力搜索,但在过去,我一直在高低搜索,以找出一种使用 VBA 代码最小化功能区的方法。对我来说,我的大多数用户都没有使用 Access 中的功能区,如果我能为他们回收屏幕空间,我会很高兴。

I know I could train them to minimize it but...well...they are users, not computer geeks. :-)

我知道我可以训练他们将其最小化,但是......好吧......他们是用户,而不是计算机极客。:-)

回答by HansUp

If your database is set up to display a particular form when it's opened, you could put this code in the form's open event:

如果您的数据库设置为在打开时显示特定表单,您可以将此代码放在表单的 open 事件中:

Private Sub Form_Open(Cancel As Integer)
    Call HideRibbon
End Sub

Here is the HideRibbon sub:

这是 HideRibbon 子:

Public Sub HideRibbon()
    'Access versions before 2007 did not have ribbon '
    'ignore error: '
    '2094, <App Name> can't find the toolbar 'Ribbon.'
    On Error Resume Next
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    On Error GoTo 0
End Sub

Edit: I changed the HideRibbon sub to eliminate On Error Resume Next. It does what I want in Access 2003 and 2007. Not sure about the string value returned by SysCmd(acSysCmdAccessVer)in all the earlier Access versions, or future Access versions.

编辑:我更改了 HideRibbon 子以消除On Error Resume Next。它在 Access 2003 和 2007 中执行我想要的操作。不确定所有早期 Access 版本或未来 Access 版本中SysCmd(acSysCmdAccessVer)返回的字符串值。

Public Sub HideRibbon()
    'Access versions before 2007 did not have ribbon '
    If Val(SysCmd(acSysCmdAccessVer)) >= 12 Then
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
    End If
End Sub