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.
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.
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,
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 |
C#
Excel.Workbook newWorkbook = this.Application.Workbooks.Add(System.Type.Missing);
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......