您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> ACCESS >> 辅导 >> 正文    
  用VBA代码处理菜单和工具栏之三 【注册男护士专用博客】          

用VBA代码处理菜单和工具栏之三

www.nanhushi.com     佚名   不详 

隐藏和显示菜单和工具栏

  可以用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")’显示已被隐藏的主菜单。

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目

      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)                            【进男护士社区逛逛】
    姓 名:
    * 游客填写  ·注册用户 ·忘记密码
    主 页:

    评 分:
    1分 2分 3分 4分 5分
    评论内容:
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。