Wednesday, October 5, 2011

Accessing the Object Model of the Host Application

To access the object model of the host application, use the Application field of the ThisAddIn class. This field returns an object that represents the current instance of the host application. The following table lists the type of the return value for the Application field in each add-in project.
Host application
Return value type
Microsoft Office Excel
Microsoft.Office.Interop.Excel.Application
Microsoft Office InfoPath
Microsoft.Office.Interop.InfoPath.Application
Microsoft Office Outlook
Microsoft.Office.Interop.Outlook.Application
Microsoft Office PowerPoint
Microsoft.Office.Interop.PowerPoint.Application
Microsoft Office Project
Microsoft.Office.Interop.MSProject.Application
Microsoft Office Visio
Microsoft.Office.Interop.Visio.Application
Microsoft Office Word
Microsoft.Office.Interop.Word.Application
The following code example shows how to use the Application field to create a new workbook in an add-in for Microsoft Office Excel. This example is intended to be run from the ThisAddIn class.
 
C#
Excel.Workbook newWorkbook = this.Application.Workbooks.Add(System.Type.Missing);
To do the same thing from outside the ThisAddIn class, use the Globals object to access the ThisAddIn class. For more information about the Globals object,
 
C#
Excel.Workbook newWorkbook = Globals.ThisAddIn.Application.Workbooks.Add(System.Type.Missing);

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

🌫️ Project Title: "Fog Buster – AI-Powered Visibility Enhancement System"

🔍 Project Vision: To design a device that allows vehicles (cars, trucks) and aircraft (planes, helicopters, drones) to see clearly during f...