Click here to Skip to main content
14,836,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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")

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

            If MyButton IsNot Nothing Then
            End If
        Catch Ex As InvalidOperationException 'Exception
        End Try

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

        With MyButton
            .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
        Test = "x"
    End Function

    Private Sub GARY3(ByVal ctrl As Office.CommandBarButton, ByRef Cancel As Boolean)
    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 ...

1 solution

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

Private Sub PressMyButton() Handles MyButton.Click

    Dim myEmailForm As New EmailForm

End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900