添加自定义按钮到主页选项卡

时间:2014-10-15 04:55:25

标签: vb.net outlook-addin outlook-vba outlook-2010

我正在尝试在Outlook 2010的默认“主页”选项卡中创建一个按钮。在VS2010中,我添加了一个commandBarButton,但它不断添加到AddIns选项卡。我想在Home选项卡中显示。

这是我的代码:

Public Class ThisAddIn
Dim newToolBar As Office.CommandBar
Dim firstButton As Office.CommandBarButton
Dim selectExplorers As Outlook.Explorers

Private Sub ThisAddIn_Startup(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Startup
    selectExplorers = Me.Application.Explorers()
    AddHandler selectExplorers.NewExplorer, AddressOf _
        Me.NewExplorer_Event
    AddToolbar()
End Sub

Private Sub NewExplorer_Event(ByVal new_Explorer _
    As Outlook.Explorer)
    new_Explorer.Activate()
    newToolBar = Nothing
    Call Me.AddToolbar()
End Sub

Private Sub AddToolbar()

   Try
        button_1 = CType(newToolBar.Controls.Add(1),  _
            Office.CommandBarButton)
        'button_1.Size = New Size(100, 50)
        'button_1.Size.Height = 42
        With button_1
            '.Style = Office.MsoButtonStyle.msoButtonCaption
            .Style = Office.MsoButtonStyle _
            .msoButtonIconAndCaption
            .Caption = "Forward Email to Loop"
            .Height = 80
        End With

        If Me.firstButton Is Nothing Then
            Me.firstButton = button_1
            AddHandler firstButton.Click, AddressOf ButtonClick
        End If

        newToolBar.Visible = True
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub

1 个答案:

答案 0 :(得分:0)

从Outlook 2010开始,使用旧版Explorer.Toolbars集合添加的按钮将添加到“添加”选项卡(专门针对尚未针对Outlook 2010更新的旧版插件而设计)。

按钮只能从COM插件添加到色带中。有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/bb398246.aspx