0
votes

How do I activate my custom class form region from a ribbon button click event? In essence, performing the same function as Outlook Home -> New Items -> Custom Forms -> My Form Name.

I’ve developed a COM AddIn presenting a form to the user. It WAS a separate form region to the IPM.Note class. But now that I’ve broken it out to with “Replace-all” and given its own class name, I’m unsure how to instantiate the form from the Ribbon class Button1_Click event handler.

I’ve struggle to find a code sample to demonstrate this detail.

If this is an Add("IPM.MyClassName") call to the item collection, I'm unsure how to code it.

2

2 Answers

0
votes

The following code works in creating an instance of my user form from a ribbon button click event.

Public Sub Button1_Click(ByVal control As Office.IRibbonControl)
    Dim oApp As Outlook.Application = Globals.ThisAddIn.Application
    Dim oNs As Outlook.NameSpace = oApp.GetNamespace("MAPI")
    Dim oInbox As Outlook.MAPIFolder = _
        oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    Dim oItems As Outlook.Items = oInbox.Items
    Dim oForm As Outlook.MailItem = oItems.Add("IPM.MyMessageClass")
    oForm.Display(False)
End Sub
0
votes

This one seems cleaner:

Public Sub Button1_Click(ByVal control As Office.IRibbonControl)
    Dim Items As Outlook.Items = _
        Globals.ThisAddIn.Application.ActiveExplorer.CurrentFolder.Items
    Dim Item As Object = Items.Add("IPM.MyMessageClass")
    Item.Display()
End Sub

When your FormRegion isn't really dependent on the folder, this one is a few lines shorter.