Reputation: 3281
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?
Upvotes: 0
Views: 5517
Reputation: 2072
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
Upvotes: 1