注册 登录
Office中国论坛/Access中国论坛 返回首页

的个人空间 http://www.office-cn.net/?0 [收藏] [复制] [分享] [RSS]

日志

隐藏和显示菜单和工具栏

已有 990 次阅读2008-2-18 10:41 |个人分类:VBA

  可以用CommandBar对象的Visible属性来隐藏和显示工具栏,当你显示一个工具栏的时候,你可以用Position属性来指定工具栏应该显示在屏幕的哪一个地方,例如,下面的一段程序需要三个参数,strCBarName表示要显示或隐藏的工具栏名称,blnVisible表示是隐藏还是要显示,可选参数lngPosition表示工具栏显示的位置,默认是显示在access窗口的上方,也可以显示在左、右或者是下方。

Function CBToolbarShow(strCBarName As String, _

                        blnVisible As Boolean, _

                        Optional lngPosition As Long = msoBarTop) As Boolean

    ' This procedure displays or hides the command bar specified in the

    ' strCBarName argument according to the value of the blnVisible

    ' argument. The optional lngPosition argument specifies where the

    ' command bar will appear on the screen.

      Dim cbrCmdBar As CommandBar

    On Error GoTo CBToolbarShow_Err

     Set cbrCmdBar = Application.CommandBars(strCBarName)

    ' Show only toolbars.

    If cbrCmdBar.Type > msoBarTypeNormal Then

        CBToolbarShow = False

        Exit Function

    End If

    ' If Position argument is invalid, set to the default

    ' msoBarTop position.

    If lngPosition < msoBarLeft or lngPosition > msoBarMenuBar Then

        lngPosition = msoBarTop

    End If

   With cbrCmdBar

        .Visible = blnVisible

        .Position = lngPosition

    End With

   CBToolbarShow = True

CBToolbarShow_End:

    Exit Function

CBToolbarShow_Err:

    CBToolbarShow = False

    Resume CBToolbarShow_End

End Function

要显示一个菜单栏,可以参考以下的一个函数来实现:

Function CBMenuBarShow(strCBarName As String) As Boolean

' 本函数可以显示一个指定的菜单栏,如果指定的菜单栏不存在或者是非法的名称,将返回FALSE

   Dim cbrCBarMenu As CommandBar

     On Error GoTo CBMenuBarShow_Err

    Set cbrCBarMenu = Application.CommandBars(strCBarName)

    If cbrCBarMenu.Type <> msoBarTypeMenuBar Then

        CBMenuBarShow = False

        Exit Function

    End If

    With cbrCBarMenu

        .Visible = True

    End With

    CBMenuBarShow = True

CBMenuBarShow_End:

    Exit Function

CBMenuBarShow_Err:

    CBMenuBarShow = False

    Resume CBMenuBarShow_End

End Function

调用方法:? CBMenuBarShow ("Menu Bar")’显示已被隐藏的主菜单。

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-29 14:49 , Processed in 0.058151 second(s), 14 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部