Excel Add-in (Plugin) Development Tips
Nov 4, 2012 · CommentsMy current side project involves creating an Excel Add-in for Excel 2007 and 2010. Here are some useful tips and “gotchas” that I came across/experienced:
- Incredibly helpful: Searching the web for Excel help can be a painful experience - follow the VSTO team’s advice! Enable the Developer ribbon, start recording a macro, complete an action, then view the resulting VBA code. It will get you most of the way!
- Use .NET 4.0 for the Excel Add-in. An immediate benefit is not having to include a bunch of Type.Missing arguments - this is automatically handled for you.
- When debugging, always close the Excel application instead of choosing “Stop Debugging” from Visual Studio.
- As a result of many debugging sessions with Excel, it can decide to “hard disable” your Addin, which causes it not to load when debugging (with no error messages!). Here’s how to fix it.
- Unit testing an Excel Add-in is very limited, so decouple your logic into separate class libraries wherever possible.
- Use a for loop to iterate through collections of Excel objects (Ranges, Cells, Worksheets, etc.) instead of a foreach loop. Otherwise, the order of the elements can be incorrect or even skipped!
- Across the Web (looking at you, MSDN!), Microsoft Office applications are often referred to by their version numbers instead of year numbers. Excel 2007 is “Excel 12.0”, Excel 2010 is “Excel 14.0”, and Excel 2013 is “Excel 15.0”.
- To switch from debugging in Excel 2010 to 2007, see here.
- If you do not use Excel 2010-specific features, your plugin will just work with Excel 2007.