OnConnection Method RRS feed

  • Question

  • I have developed an MS Office 2010 Backstage UI. It looks like it in the OnConnection Method we link the XML resource that has to be displayed in the office
    using System;
    using System.Reflection;
    using System.IO;
    using System.Xml;
    using Microsoft.Office.Core;
    using Extensibility;
    using System.Runtime.InteropServices;
    using appWord = Microsoft.Office.Interop.Word;
    using appExcel = Microsoft.Office.Interop.Excel;
    using System.Windows.Forms;

    private appWord.Application applicationObject;
    private appExcel.Application applicationExcel;
    private object addInInstance;
    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
          applicationObject = (appWord.Application)application;
          addInInstance = addInInst;
          //applicationExcel = (appExcel.Application)application;
          //addInInstance = addInInst;

    Now I highlighted the Excel part because both things cannot be initialzied at the same time. So in this OnConnection Method is there a switch or a conditional statement through which I can figure out if MS Word is open it should execute first statement in case MS Excel is opened it should execute Statement 2?

    Friday, July 15, 2011 9:27 AM


  • Hi Adeel,

    As far as I know, you do not need to instantiate the application according to some conditional statement. If you have checked the AddIn for Excel and Word, it can be installed both for them and just keep the same, you do not need to change it.

            	private object applicationObject;
            	private object addInInstance;
    		/// <summary>
    		///      Implements the OnConnection method of the IDTExtensibility2 interface.
    		///      Receives notification that the Add-in is being loaded.
    		/// </summary>
    		/// <param term='application'>
    		///      Root object of the host application.
    		/// </param>
    		/// <param term='connectMode'>
    		///      Describes how the Add-in is being loaded.
    		/// </param>
    		/// <param term='addInInst'>
    		///      Object representing this Add-in.
    		/// </param>
    		/// <seealso class='IDTExtensibility2' />
    		public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
    			applicationObject = application;
    			addInInstance = addInInst;

    You can try it by adding a pop up message box, it can show for Word and Excel when starting the applications.

    Hope you can figure it out and just feel free to follow up after you have tried. Wish you a nice day.

    Best Regards,

    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by maverick786us Wednesday, July 20, 2011 10:42 AM
    Wednesday, July 20, 2011 3:37 AM