This problem is making me crazy.
Actually I have multiple problems.
First one:
Why on earth are is there a _Worksheet and a Worksheetinterface in the Excel interop. They both look the same, except for some attributes on the methods.
It’s confusing!
Second of all: my job today is making a VB.NET file more strict, by settings Option Strict On and Option Explicit On
While it works for most files, I’m bumping into a problem.
Here’s a little code piece:
Private _pivotTable As Excel.PivotTable
With _pivotTable
pvf = .AddDataField(pvc)
End With
PivotTable.AddDataField is defined on the MSDN page: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.pivottable.adddatafield(office.11).aspx
When I check my local Interop dll w/ Reflector that method is NOT there.
When I run the application, and step through it, the method just works.
When I try to step INTO the method, I get an LateBound Exception.
WTF?
So the question is: why are the interfaces defined more than once (twice sometimes?).
2nd question. AddDataField trouble
Some of the items that are supposedly there according to msdn are not actually there within VB. I found this was the case quite a few times. Interestingly, these properties or methods are available in VBA, but not in VB.NET. To get around this, I actually created a temporary macro within the excel file I was editing, included the code to manipulate the things I couldn’t get at otherwise, and then ran it. So, it was actually VBA code written as a string in VB.NET and executed in Excel.
Here’s the code from that project. Maybe it’ll help: