Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba Outlook自定义菜单按钮_Vba_Outlook_Menubar - Fatal编程技术网

Vba Outlook自定义菜单按钮

Vba Outlook自定义菜单按钮,vba,outlook,menubar,Vba,Outlook,Menubar,我有两个菜单按钮,我想添加在outlook菜单后的帮助菜单。我编写了添加按钮的代码,但每次我重新打开outlook时,它只会再添加两个按钮,即使这两个菜单按钮已经存在。欢迎任何帮助 Function ToolBarExists(strName As String) As Boolean Dim tlbar As commandBar For Each tlbar In ActiveExplorer.CommandBars If tlbar.Name = strName Then

我有两个菜单按钮,我想添加在outlook菜单后的帮助菜单。我编写了添加按钮的代码,但每次我重新打开outlook时,它只会再添加两个按钮,即使这两个菜单按钮已经存在。欢迎任何帮助

Function ToolBarExists(strName As String) As Boolean
Dim tlbar As commandBar
    For Each tlbar In ActiveExplorer.CommandBars
     If tlbar.Name = strName Then
        ToolBarExists = True
        Exit For
    End If
Next tlbar
End Function

Sub TBarExistsbutton1()
    If ToolBarExists("button1") Then
        If ActiveExplorer.CommandBars("button1").Visible = True Then
            ActiveExplorer.CommandBars("button1").Visible = False
        Else
            ActiveExplorer.CommandBars("button1").Visible = True
        End If
    Else
        Call a123
    End If

End Sub
Sub TBarExistsbutton2()
    If ToolBarExists("button2") Then
        If ActiveExplorer.CommandBars("button2").Visible = True Then
            ActiveExplorer.CommandBars("button2").Visible = False
        Else
            ActiveExplorer.CommandBars("button2").Visible = True
        End If
    Else
        Call a1234
    End If
    End Sub

Sub a123()
Dim outl As Object
Dim msg As Object
Set outl = CreateObject("Outlook.Application")
Dim objBar As Office.commandBar
Dim objButton As Office.commandBarButton
Set objBar = Application.ActiveWindow.CommandBars("Menu Bar")
Set objButton = objBar.Controls.Add(msoControlButton)
    With objButton
    .caption = "button1"
    .onAction = "macro1"
    .faceId = 487
    .Style = msoButtonIconAndCaption
End With
End Sub

Sub a1234()
Dim outl As Object
Dim msg As Object
Set outl = CreateObject("Outlook.Application")
Dim objBar As Office.commandBar
Dim objButton As Office.commandBarButton
Set objBar = Application.ActiveWindow.CommandBars("Menu Bar")
Set objButton = objBar.Controls.Add(msoControlButton)
With objButton
    .caption = "button2"
    .onAction = "macro2"
    .faceId = 487
    .Style = msoButtonIconAndCaption
End With
End Sub

在Outlook 2010中。如果Visible对您有效,请以类似的方式将其合并

Option Explicit

Sub TBarExistsbutton1()

    Dim cbControlCount As Long
    Dim button1Found As Boolean
    Dim j As Long

    If ToolBarExists("Menu Bar") Then

        cbControlCount = ActiveWindow.CommandBars("Menu Bar").Controls.count
        Debug.Print " There are " & cbControlCount & " controls in " & "Menu Bar"

        For j = 1 To cbControlCount
            Debug.Print ActiveWindow.CommandBars("Menu Bar").Controls(j).Caption
            If ActiveWindow.CommandBars("Menu Bar").Controls(j).Caption = "button1" Then
                button1Found = True
                Exit For
            End If
        Next j

        If button1Found = False Then a123

    Else
        Debug.Print "Menu Bar does not exist."
        a123

    End If

End Sub

什么时候使用函数ToolBarExists(strName作为字符串)作为布尔值?您好,该函数应该检查现有的工具栏,我有大约10个。它应该按工具栏的名称进行检查。