![]() The Wb parameter of the event handler for the WorkbookBeforeSave event. The Application field returns a Application object, which represents the current instance of Excel. The Application field of the ThisAddIn class. To modify the workbook when it is saved, the previous code examples use the following objects: += new .AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave) This code is used to connect the Application_WorkbookBeforeSave event handler with the WorkbookBeforeSave event. If you are using C#, add the following required code to the ThisAddIn_Startup event handler. NewFirstRow.Value2 = "This text was added by using code" Private Sub Application_WorkbookBeforeSave(ByVal Wb As .Workbook, ByVal SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles Application.WorkbookBeforeSaveĭim activeWorksheet As Excel.Worksheet = CType(Application.ActiveSheet, Excel.Worksheet)ĭim firstRow As Excel.Range = activeWorksheet.Range("A1")į()ĭim newFirstRow As Excel.Range = activeWorksheet.Range("A1") Void Application_WorkbookBeforeSave(.Workbook Wb, bool SaveAsUI, ref bool Cancel)Įxcel.Worksheet activeWorksheet = ((Excel.Worksheet)Application.ActiveSheet) Įxcel.Range firstRow = activeWorksheet.get_Range("A1") į() Įxcel.Range newFirstRow = activeWorksheet.get_Range("A1") When the user saves a workbook, the event handler adds new text at the start of the active worksheet. The new code defines an event handler for the WorkbookBeforeSave event, which is raised when a workbook is saved. In the ThisAddIn code file, add the following code to the ThisAddIn class. To add a line of text to the saved workbook For more information, see Events in Office projects. Use these event handlers to initialize your VSTO Add-in when it is loaded, and to clean up resources used by your Add-in when it is unloaded. These event handlers are called when Excel loads and unloads your VSTO Add-in. The ThisAddIn_Startup and ThisAddIn_Shutdown event handlers. The remainder of the ThisAddIn class is defined in a hidden code file that you should not modify. For more information, see Program VSTO Add-ins. This class provides an entry point for your code and provides access to the object model of Excel. By default, the ThisAddIn code file contains the following generated code:Ī partial definition of the ThisAddIn class. The active worksheet is the worksheet that is open when the user saves the workbook. The new code uses the object model of Excel to insert boilerplate text in the first row of the active worksheet. Next, add code to the ThisAddIn code file. Write code to add text to the saved workbook Visual Studio creates the FirstExcelAddIn project and opens the ThisAddIn code file in the editor. In the list of project templates, select Excel 2010 Add-in or Excel 2013 Add-in. Under the expanded Office/SharePoint node, select the Office Add-ins node. In the templates pane, expand Visual C# or Visual Basic, and then expand Office/SharePoint. On the File menu, point to New, and then click Project. ![]() For more information, see Configure a computer to develop Office solutions.Ĭreate the project To create a new Excel VSTO Add-in project in Visual Studio You need the following components to complete this walkthrough:Īn edition of Visual Studio that includes the Microsoft Office developer tools. For more information, see Personalize the IDE. The Visual Studio edition that you have and the settings that you use determine these elements. Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |