Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Trouble with vs 2008 excel add in walk through

Trouble with vs 2008 excel add in walk through

Trouble with vs 2008 excel add in walk through

I'm having some problems with  msdn tutorial http://msdn.microsoft.com/en-us/library/cc668205.aspx

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,
Here's the code as it stands


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);
        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


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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close