Beginning VSTO Development

Yeah, it can get confusing, especially given the skip-level naming conventions, etc. Essentially, you’ll need: Full version (not Express) of Visual Studio and the .NET version you’re targetting. One of the VSTO run times (VSTO 2003, VSTO 2005, VSTO 2005 SE, VSTO 2008, VSTO 2010). For what your asking, VSTO 2005 SE is probably your … Read more

BUG: Can’t choose dates on a DatePicker that fall outside a floating VSTO Add-In

“Floating” is the key to the problem here. What’s never not a problem (occasionally responsible for odd things) is relying on the message pump in Excel to dispatch Windows messages, the messages that make these controls respond to input. This goes wrong in WPF as much as Winforms, they have their own dispatch loop that … Read more

How to reference Microsoft.Office.Interop.Excel dll?

Use NuGet (VS 2013+): The easiest way in any recent version of Visual Studio is to just use the NuGet package manager. (Even VS2013, with the NuGet Package Manager for Visual Studio 2013 extension.) Right-click on “References” and choose “Manage NuGet Packages…”, then just search for Excel. VS 2012: Older versions of VS didn’t have … Read more

How do I create a real-time Excel automation add-in in C# using RtdServer?

(As an alternative to the approach described below you should consider using Excel-DNA. Excel-DNA allows you to build a registration-free RTD server. COM registration requires administrative privileges which may lead to installation headaches. That being said, the code below works fine.) To create a real-time Excel automation add-in in C# using RtdServer: 1) Create a … Read more

Excel error HRESULT: 0x800A03EC while trying to get range with cell’s name

The error code 0x800A03EC (or -2146827284) means NAME_NOT_FOUND; in other words, you’ve asked for something, and Excel can’t find it. This is a generic code, which can apply to lots of things it can’t find e.g. using properties which aren’t valid at that time like PivotItem.SourceNameStandard throws this when a PivotItem doesn’t have a filter … Read more

How to open an Excel file in C#?

You need to have installed Microsoft Visual Studio Tools for Office (VSTO). VSTO can be selected in the Visual Studio installer under Workloads > Web & Cloud > Office/SharePoint Development. After that create a generic .NET project and add a reference to Microsoft.Office.Interop.Excel via ‘Add Reference… > Assemblies’ dialog. Application excel = new Application(); Workbook … Read more

Fastest way to interface between live (unsaved) Excel data and C# objects

I’ll take this as a challenge, and will bet the fastest way to shuffle your data between Excel and C# is to use Excel-DNA – http://excel-dna.net. (Disclaimer: I develop Excel-DNA. But it’s still true…) Because it uses the native .xll interface it skips all the COM integration overhead that you’d have with VSTO or another … Read more

Excel Interop – Efficiency and performance

When using C# or VB.Net to either get or set a range, figure out what the total size of the range is, and then get one large 2 dimensional object array… //get values object[,] objectArray = shtName.get_Range(“A1:Z100”).Value2; iFace = Convert.ToInt32(objectArray[1,1]); //set values object[,] objectArray = new object[3,1] {{“A”}{“B”}{“C”}}; rngName.Value2 = objectArray; Note that its important … Read more