|
abraxas (Programmer) |
16 Dec 09 20:42 |
Hello, I'm having some problems with msdn tutorial http://msdn.microsoft.com/en-us/library/cc668205.aspxExcel opens but the string that was supposed to be in A1 is not there ie "This text was added by using code" I did everything as per instruction Create Project Excel 2007 Add In Copied code to relevant methods and events Ran it, Nothing Here's the code as it stands CODEnamespace FirstExcelAddIn { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.WorkbookBeforeSave += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave); }
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { }
#region VSTO generated code
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion void Application_WorkbookBeforeSave(Microsoft.Office.Interop.Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel) { Excel.Worksheet activeWorksheet = ((Excel.Worksheet)Application.ActiveSheet); Excel.Range firstRow = activeWorksheet.get_Range("A1", missing); firstRow.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown, System.Type.Missing); Excel.Range newFirstRow = activeWorksheet.get_Range("A1", missing); newFirstRow.Value2 = "This text was added by using code"; }
} } For a bit of fun I threw in a CODEthrow new System.Exception("An exception has occurred."); as the first line of the Application_WorkbookBeforeSave() method. It didn't throw. I get the impression the startup event is prevented from firing the attached method??? Using visual studio 2008, office 2007 pro, vista 64 and running as unlocked administrator (that's a private grievance). I checked for security settings in this type of project but there aren't any ie Project Properties > Security. Not there. Sincere thanks for someone to click on link Anthony Lawrence Compliments of the season to you |
|