Question : System.NullReferenceExcept<wbr />ion for Excel.Workbooks.Open (visual Studio

Visual Studio 2003 error message.
Error message prompted "System.NullReferenceException: Object reference not set to an instance of an object.  at Microsoft.Office.Interop.Excel.Workbooks.Open" while open excel at user's computer (MS XP Service Pack 3, Office 2000).

It work fine at my development computer (NS XP Service Pack 2, Office 2007).

Part of coding:

Imports Microsoft.Office.Interop

Dim App As New Excel.Application
App.Visible = False
App.Application.SheetsInNewWorkbook = 1
Dim Destination As Excel.Workbook = App.Workbooks.Open("C:\Test.xls")

Any help is very much appreciated...

Answer : System.NullReferenceExcept<wbr />ion for Excel.Workbooks.Open (visual Studio

For Office 2000 you need version 9 of the office object library. available in the com tab.
If you do not have it, use tlbimp to generate it.
Check:
http://msdn.microsoft.com/en-us/library/aa679806(office.11).aspx#officeinteroperabilitych2_part1_97and2000
Quoting from the link:
"In either case, the general pattern is to right-click the project in Solution Explorer and select Add Reference. Click the COM tab. Then select the appropriate type libraryfor example, for Excel you would select the following:
Office 2000: Microsoft Excel 9.0 Object Library

For Office 97 and Office 2000, this triggers TlbImp to generate a new IA based on the selected type library. You should also find that references have been added for the ancillary Office core and Visual Basic extensibility PIAs. Note that the minimum requirement is Office 97 with Service Release 1 (SR-1). The general behavior of the tools listed (as they are used from within Visual Studio .NET) is described in Table 2-2.
"

Note: Only Office XP onwards have precompiled PIA.
I know dealing with this version mess is a pain, but M$ did a poor job with office integration. The better versions to integrate are Office 2003 and 2007 - in my case we only support those two versions in our product. it is very risky to support and test multiple office versions + service packs + operative systems.
Random Solutions  
 
programming4us programming4us