Solved

outlook add-on button

Posted on 2009-04-07
6
251 Views
Last Modified: 2013-11-26
Using VB.net how can I create a button in an outlook add-on to outllook 2007 and hook it to a Click event that calls a function
0
Comment
Question by:qwerty360
  • 3
  • 3
6 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, qwerty360.

Create a button where?  A form, the ribbon, in a pane, etc.?
0
 

Author Comment

by:qwerty360
Comment Utility
Acutally I am adding a menu item under the "Actions" menu. I was able to add a menu item but I am having trouble now adding an onclick kind of event. I tried the OnAction property but it does not seem to work. Please see the atached code snippet. Thanks.
    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

        Dim ActionsCmdBar As Office.CommandBar = Me.Application.Explorers(1).CommandBars("Actions")

        Dim myMenuItem As Office.CommandBarButton = ActionsCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)

        myMenuItem.Caption = "My Menu Item"

        myMenuItem.OnAction = "display_message"

    End Sub
 

    Sub display_message()

        Microsoft.VisualBasic.MsgBox("test")

    End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Sorry to be slow getting back to you.

Try changing the declaration of display_message to

    Public Sub display_message()
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:qwerty360
Comment Utility

I changed it to  " Public Sub display_message()"  but still nothing happens when I click on the menu item
0
 

Accepted Solution

by:
qwerty360 earned 0 total points
Comment Utility
I got it to work using "WithEvents" in the following code
   Private WithEvents myMenuItem As Office.CommandBarButton

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

        Try

            Dim ActionsCmdBar As Office.CommandBar = Me.Application.Explorers(1).CommandBars("Actions")

            Dim cbb As Office.CommandBarControl

            For Each cbb In ActionsCmdBar.Controls

                If cbb.Caption = "My Menu Item" Then

                    cbb.Delete()

                End If

            Next

            myMenuItem = ActionsCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)

            myMenuItem.Caption = "My Menu Item"

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub
 

    Private Sub myMenuItem_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, _

    ByRef CancelDefault As Boolean) Handles myMenuItem.Click

        Try

            System.Windows.Forms.MessageBox.Show("test")

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try
 

    End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Good deal  Glad you have a solution.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Outlook Free & Paid Tools
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now