faqts : Computers : Programming : Languages : C# : Office Add-in Development

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 5 people (40%) answered Yes
Recently 2 of 5 people (40%) answered Yes

Entry

How can I get the application object to start working with?
I've generated the add-in code in VS, what do I do next?

Mar 22nd, 2002 08:26
Nathan Wallace, http://aspn.activestate.com/ASPN/Mail/Message/DevelopMentor-dotNET/908104


Before you can do anything useful in an office add-in you have to have 
the application object.  This is the basic object from which 
everything for the application that you are adding into is available.
VS.NET has this object as applicationObject.  Unfortunately they have 
it of type _COMObject.  This isn't a very useful form.  The trick is 
to cast this object to be like the application object (obvious once 
you know).
Here is the code you want:
    myApp = (Excel.Application) applicationObject;
Make sure Excel (or whatever office app) is in the namespace.  You can 
do this by adding references to the appropriate office DLLs and then 
adding "using" directives to the top of your C# namespace.
Try some code like this in the OnBeginShutdown method to see if you 
are on the right track:
    Excel.Application myApp = null;
    try 
    { 
        myApp = (Excel.Application) applicationObject; 
    } 
    catch(System.Exception e) 
    { 
        MessageBox.Show(e.Message); 
    }