0

I am just a beginner in excel add-in's. Created excel add-in and wrote a simple variable assignment code in startup event.

My code

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    string path = this.Application.ThisWorkbook.Path;
}         

When F5 is pressed from visual studio, new empty excel file is opened and breakpoint hits this event. Ideally you want to test the add-in on existing excel file to check modifications that your add-in is expected to do? Can the existing file be used for debugging?

3
  • Please re-phrase your question. Commented Dec 15, 2014 at 10:21
  • What is your problem more precisely. You are having problem debuging your addin with existing files? Commented Dec 15, 2014 at 10:24
  • Yes. that's correct.when I press f5, addin debugging point is hit with new excel file launched from visual studio.Want to debug with existing file. Commented Dec 15, 2014 at 10:27

1 Answer 1

1

You should move the code string path = this.Application.ThisWorkbook.Path; from this startup code to WorkbookOpen handler code.

This is because, during normal startup of addins, there is no workbook already loaded. Most of the time you will get null for ThisWorkbook in startup time. So during startup of code, add event handler for handling WorkbookOpen event.

In the method which handles the WorkbookOpen Event, add your code to get the path of file.

Now for debugging:

(Default and Recommended)

In VS press F5. In the launched Excel, open your excel file and start debugging.

OR

Start Excel. Open your file. In VS, goto Tools->Attach To Process-> Find Excel.exe and double click.

OR

In project properties, Debug-> Select start external program -> Type the full path to access and add the excel file full path as argument

Sign up to request clarification or add additional context in comments.

3 Comments

All 3 do not work. 1)Attach to process does not hit breakpoint , even though existing excel is open. 2)When F5 is pressed,add-In startup code runs on newly opened excel already, hence opening new excel using open menu has no effect. 3)Do you example of this?
Well these methods are used when a direct method is not supplied for debugging libraries. I have many example of these. Can you elaborate your question and show some code? Where you are putting breakpoints...
Are you putting breakpoint on a method which handles the event of WorkbookOpen?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.