在Outlook 2007中向标准工具栏添加一个按钮 [英] Add a Button to Standard Toolbar in Outlook 2007

查看:205
本文介绍了在Outlook 2007中向标准工具栏添加一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过几千次Google搜索找到了一些代码,为标准Outlook工具栏添加了一个按钮...但是,当我点击该按钮时,没有任何反应......是否有人能够告诉我原因?



I have found some code, via a few thousand Google searches, that adds a button to the Standard Outlook Toolbar ... however, when I click on that button, nothing happens ... is anybody able to tell me why ?

Imports Microsoft.Office.Interop.Outlook
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Imports System.Text.RegularExpressions
Imports Microsoft.Office.Core

Public Class ThisAddIn

    Dim WithEvents MyApp As Outlook.Application = Nothing
    Dim MyNS As Outlook.NameSpace = Nothing
    Dim WithEvents MyButton As Office.CommandBarButton

    Private Sub ThisAddIn_Startup() Handles Me.Startup

        Dim StandardToolbar As Office.CommandBar = Application.ActiveExplorer.CommandBars("Standard")

        AddButton(ButtonCaption:="GARY1", ButtonTag:="GARY2", ButtonIcon:=3)

        MyApp = Application
        MyNS = MyApp.GetNamespace("MAPI")

    End Sub

    Private Sub AddButton(ByVal ButtonCaption As String, ByVal ButtonTag As String, ByVal ButtonIcon As String)
        Dim MyButton As Office.CommandBarButton
        Dim StandardToolbar As Office.CommandBar = Application.ActiveExplorer.CommandBars("Standard")

        Try
            ' If the button already exists, remove it
            MyButton = StandardToolbar.FindControl(Tag:=ButtonTag)

            If MyButton IsNot Nothing Then
                MyButton.Delete(True)
            End If
        Catch Ex As InvalidOperationException 'Exception
            MsgBox(Ex.Message)
        End Try

        'create the control
        MyButton = CType(StandardToolbar.Controls.Add(Type:=1, Before:=8, Temporary:=True), Office.CommandBarButton)

        With MyButton
            '.Picture
            .Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
            .Caption = ButtonCaption
            .Tag = ButtonTag
            .FaceId = ButtonIcon
            .OnAction = "!<ThisAddIn.Test>"
        End With

        AddHandler MyButton.Click, AddressOf GARY3
    End Sub

    Public Function Test() As String
        MsgBox("Test")
        Test = "x"
    End Function

    Private Sub GARY3(ByVal ctrl As Office.CommandBarButton, ByRef Cancel As Boolean)
        MsgBox("GARY4")
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub





这个程序不仅仅是这个代码,因此额外的进口,但它是独立于这个过程。



任何帮助表示感谢...



There is more to this program than just this code, hence the extra imports, but it is independent to this process.

Any help appreciated ...

推荐答案

我需要处理一个MyButton 。点击...... DOH !!!



I needed to handle a MyButton.Click ... DOH !!!

Private Sub PressMyButton() Handles MyButton.Click

    Dim myEmailForm As New EmailForm
    myEmailForm.Show()

End Sub


这篇关于在Outlook 2007中向标准工具栏添加一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆