VSTO 从功能区调用 ThisAddIn 方法 Class

VSTO Call ThisAddIn Method from Ribbon Class

我有一个简单的问题。我有一个小的 Outlook 加载项。现在我想给它添加一个功能区,用于手动执行方法。

public partial class ThisAddIn
{
    Outlook.NameSpace outlookNameSpace;
    Outlook.MAPIFolder inbox;
    Outlook.Items items;
    Outlook.MAPIFolder destinationFolder = null;
    Outlook.MAPIFolder rootFolder = null;
    //Outlook.Folders rootFolderFolders = null;
    Outlook.Store store = null;



    protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
        return new MyRibbon();
    }



    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {

        outlookNameSpace = this.Application.GetNamespace("MAPI");
        inbox = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
        items = inbox.Items;
        items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);

    }

       public void RibbonAction()
        {

            MessageBox.Show("Action Found Class");
            Outlook.Explorer currentExplorer = null;
            currentExplorer = this.Application.ActiveExplorer();


        }

和MyRibbon.cs

public class MyRibbon : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public MyRibbon()
        {
        }

        public void OnTextButton(Office.IRibbonControl control)
        {
                        
thisAddIn.RibbonAction();

        }

我想遍历 Outlook 资源管理器中的选定项目。看来我不能在 MyRibbon 中执行此操作,所以我想在 thisAddIn 中实现该方法。但是Visual Studio让我不要这样做。

由于classThisAddIn中好像没有使用函数RibbonAction(),这里删除,直接在class中插入函数MyRibbon.

要像 ThisAddIn class 中那样在其他地方获取 ActiveExplorer,您可以使用以下代码:

Outlook.Explorer activeExplorer = Globals.ThisAddIn.Application.ActiveExplorer();