VSTO is Microsoft's launch of a technology for Office products that provides class libraries to make it easier for developers to develop Office solutions that extend functionality to Word/excel/outlook.
New->excel 2013 External Program
After the project has been created successfully
Only the ThisAddIn.cs file, which has the ThisAddIn_Startup and ThisAddIn_Shutdown two methods, can be known from the naming of two methods, if your code wants to run when the add-in is loaded, Put the code in the ThisAddIn_Startup method content, and if you want to run your code when the add-in is unloaded, put the code inside the ThisAddIn_Shutdown method.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Xml.Linq;usingExcel =Microsoft.Office.Interop.Excel;usingOffice =Microsoft.Office.Core;usingMicrosoft.Office.Tools.Excel;usingSystem.Windows.Forms;namespaceexceladdin1{ Public Partial classThisAddIn {Private voidThisAddIn_Startup (Objectsender, System.EventArgs e) {MessageBox.Show ("Welcome to Microsoft Excel"); } Private voidThisAddIn_Shutdown (Objectsender, System.EventArgs e) {MessageBox.Show ("Thanks for using! "); } #regionCode generated by VSTO/// <summary> ///The Designer supports the required method-do not///Use the Code Editor to modify the contents of this method. /// </summary> Private voidInternalstartup () { This. Startup + =NewSystem.EventHandler (ThisAddIn_Startup); This. Shutdown + =NewSystem.EventHandler (ThisAddIn_Shutdown); } #endregion }}
After adding the code F5 run, you can see windows that are welcome to Microsoft Excel when you start Excel, and a thank you window when exiting.
One of the VSTO development