FrontPage VBA教程:CommandBars属性

返回表示 Microsoft FrontPage 所显示的菜单和工具栏的CommandBars对象。

注释

使用命令栏不可以访问 FrontPage 特有的弹出式快捷菜单。例如,不能访问右键单击“网页”视图中的网页时所出现的快捷菜单。但是使用CommandBar对象的ShowPopup方法可以创建自己的弹出式快捷菜单。

VBA示例

下列三个过程在工具栏上设置新的菜单项。

过程 1:


Sub AddMenuItem()
    Dim newMenu As CommandBarControl
    Dim toolsMenu As CommandBar
    Set toolsMenu = Application.CommandBars("Tools")
    Set newMenu = _
            toolsMenu.Controls.Add(msoControlButton, , , , True)
    newMenu.Caption = "New &Menu Item"
End Sub

下一个过程将 Click事件关联到自定义按钮上,而且必须将它添加到类或表单模块中。所显示的模块是表单模块。该过程在“工具”菜单上添加新项目,然后通过将变量e_NewMenu(用在WithEvents 语句中)分配给自定义按钮变量newMenu 来关联自定义按钮的事件。

过程 2:


Private Sub AddButton_Click()
    Dim newMenu As CommandBarControl
    Dim WithEvents e_NewMenu As CommandBarButton
    Sub AddMenuItemWithEventHook()
        Dim toolsMenu As CommandBar
        Set toolsMenu = Application.CommandBars("Tools")
        Set newMenu = _
                toolsMenu.Controls.Add(msoControlButton, , , , True)
        Set e_NewMenu = newMenu
        newMenu.Caption = "New &Menu Item"
    End Sub
Private Sub e_NewMenu_Click(ByVal Ctrl As _
        Office.CommandBarButton, CancelDefault As Boolean)
    MsgBox "Menu Item Clicked"
    Ctrl.Caption = "Clicked"
End Sub

若要使用 CommandBars集合来执行 FrontPage 的自定义菜单项,请将该菜单项进行索引,并调用该项目的 Execute方法。下列示例在插入点处插入 Microsoft Office 电子表格控件。

过程 3:


Sub ExecuteMenu()
    Dim I As String
    Dim C As String
    Dim O As String
    I = "Insert"
    C = "C&omponent"
    O = "Office Sp&readsheet"
    CommandBars(I).Controls(C).Controls(O).Execute
End Sub

下列示例返回当前站点中命令栏的各个属性的状态。


Private Sub GetCommandBars()
    Dim myWeb As WebEx
    Dim myCB As Object
    Dim myCBCount As Integer
    Dim myDisplayFonts As Boolean
    Dim myDisplayKeysInToolTips As Boolean
    Dim myLargeButtons As Boolean
    Dim myMenuAnimationStyle As String
    Set myWeb = ActiveWeb
    Set myCB = Application.CommandBars
    With myCB
            myCBCount = .Count
            myDisplayFonts = .DisplayFonts
            myDisplayKeysInToolTips = .DisplayKeysInTooltips
            myLargeButtons = .LargeButtons
            myMenuAnimationStyle = .MenuAnimationStyle
    End With
End Sub

下列示例在命令栏中循环并返回每个菜单的几个属性。

注意  若要运行本示例,请创建含有名为txtComBar 的文本框以及名为cmdComBar 的命令按钮的表单,然后将下列代码复制到代码窗口中。


Private Sub cmdComBar_Click()
    Dim myWeb As WebEx
    Dim myComBars As Object
    Dim myComBar As Object
    Dim myText As String
    Dim myName As String
    Dim myAdaptMenu As String
    Dim myEnabledMenu As String
    Dim myMenuHeight As String
    Dim myMenuWidth As String
    Set myWeb = ActiveWeb
    Set myComBars = Application.CommandBars
    myName = "Name: "
    myAdaptMenu = "Menu Adaptive? "
    myEnabledMenu = "Menu Enabled? "
    myMenuHeight = "Menu Height: "
    myMenuWidth = "Menu Width: "
    txtComBar.Locked = True
    txtComBar.maxLength = 10000
    txtComBar.MultiLine = True
    txtComBar.ScrollBars = fmScrollBarsVertical
    With myComBars
        For Each myComBar In myComBars
            With myComBar
                myText = myText & myName & .Name & vbCrLf
                myText = myText & myAdaptMenu & .AdaptiveMenu & vbCrLf
                myText = myText & myEnabledMenu & .Enabled & vbCrLf
                myText = myText & myMenuHeight & .Height & vbCrLf
                myText = myText & myMenuWidth & .Width & vbCrLf
                txtComBar.Text = myText
            End With
        Next
        txtComBar.SetFocus
        txtComBar.CurLine = 0
    End With
End Sub

上页:FrontPage VBA教程:COMAddIns属性 下页:FrontPage VBA教程:ConnectionSpeed属性

FrontPage VBA教程:CommandBars属性

FrontPage VBA教程:ConnectionSpeed属性 FrontPage VBA教程:Count属性
FrontPage VBA教程:Creator属性 FrontPage VBA教程:Currency属性
FrontPage VBA教程:currentStyleState属性 FrontPage VBA教程:defaultCharset属性
FrontPage VBA教程:DefaultValue属性 FrontPage VBA教程:DefaultViewPage属性
FrontPage VBA教程:Description属性 FrontPage VBA教程:DesignSecurity属性
FrontPage VBA教程:DisplayForm属性 FrontPage VBA教程:DisplayFormat属性
FrontPage VBA教程:Document属性 FrontPage VBA教程:DocumentHTML属性
FrontPage VBA教程:domain属性 FrontPage VBA教程:DownloadTime属性
FrontPage VBA教程:EditForm属性 FrontPage VBA教程:EditSecurity属性
FrontPage VBA教程:embeds属性 FrontPage VBA教程:Extension属性
版权所有 © 中山市飞娥软件工作室 证书:粤ICP备09170368号