I wrote an Add-in for Outlook 2010 that inserts text to a new email subject and to the email body. The working code is shown below.
Later I added a custom group to the built-in new email message tab ribbon and added a button using the default name Button1. When I run the add-in the button shows up fine.
I want to click on this button and change the subject and the body content. I tried to add a private sub Button1_Click with code that changes the subject to “subject example” and the body to “body example” and could not make it work. Can you add to the ribbon code the Button1_Click sub that will do that? See below the Addin code and the ribbon1 code.
Public Class ThisAddIn
Private WithEvents inspectors As Outlook.Inspectors
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
inspectors = Me.Application.Inspectors
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
If Not (mailItem Is Nothing) Then
If mailItem.EntryID Is Nothing Then
mailItem.Subject = "This text was added by using code"
mailItem.Body = "This text was added by using code"
End If
End If
End Sub
End Class
Ribbon1 Code without the Private Sub Button1.Click. Please show me how to write this code.
Public Class Ribbon1
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
End Sub
End Class