Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with vs 2008 excel add in walk through

Status
Not open for further replies.

abraxas

Programmer
Jan 15, 2001
75
0
0
AU
Hello,
I'm having some problems with msdn tutorial
Excel 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
Code:
namespace 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
Code:
throw 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top