Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...My thanks to the contributors who freely share their knowledge and enthusiasms. This forum restores some measure of my faith in human nature..."

Geography

Where in the world do Tek-Tips members come from?

Trouble with vs 2008 excel add in walk through

abraxas (Programmer)
16 Dec 09 20:42
Hello,
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,
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



  

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!

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