Excel Automation error in VB.Net -- System.NullReferenceException : Object reference not set

C

Chuck

I created a VB.net app that opens a current excel workbook, puts some
data in it and saves it.

This works fine on all XP machines. But I am getting an error on win
98 machines.

here a portion of the code...

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Office.Core

Public Class Form2
Inherits System.Windows.Forms.Form


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim oSheet As Object
Dim oExcel As New Excel.Application
Dim oBooks As Excel.Workbooks
oBooks = oExcel.Workbooks
Dim oBook = oExcel.Workbooks.Open("C:\MyWorkbook.xls")--> THIS
LINE IS CAUSING THE ERROR

-----------------

************** Exception Text **************
System.NullReferenceException:

Object reference not set to an instance of an object. at
Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object
ReadOnly, Object Format, Object Password, Object WriteResPassword,
Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter,
Object Editable, Object Notify, Object Converter, Object AddToMru,
Object Local, Object CorruptLoad)

at MyProj.Form2.Button1_Click(Object sender, EventArgs e) in
C:\MyWorkbook.xls Form2.vb:line 161


at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
 
O

One Handed Man \( OHM - Terry Burns \)

The question I have is what version of Excel is running on the Win98
Machine, it is possible you have an old version which does not support this
function.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
C

chuck a

Thanks for the reply. The win 98 machines are running Office 2000...
Is there another command I could use that would be compatible with
office 2000 and 2003

TIA

Chuck
 
O

One Handed Man \( OHM - Terry Burns \)

This is the function for Excel 5.0 ( I think this is the same as 2000 ), it
requires an object rather than a string. Maybe you could box the string and
try it that way, Im clutching at straws really

EXCEL.wORKBOOKS.OPEN

Public Overridable Function

Open(ByVal Filename As Object,
Optional ByVal UpdateLinks As Object = Nothing,
Optional ByVal ReadOnly As Object = Nothing,
Optional ByVal Format As Object = Nothing,
Optional ByVal Password As Object = Nothing,
Optional ByVal WriteResPassword As Object = Nothing,
Optional ByVal IgnoreReadOnlyRecommended As Object = Nothing,
Optional ByVal Origin As Object = Nothing,
Optional ByVal Delimiter As Object = Nothing,
Optional ByVal Editable As Object = Nothing,
Optional ByVal Notify As Object = Nothing,
Optional ByVal Converter As Object = Nothing) As Object

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
G

Guest

You might try importing the reference to previous versions of Excel in your
application if you don't need the functionallity of later versions. The
later versions should recognize at least most of the earlier version
functionality.
 
O

One Handed Man \( OHM - Terry Burns \)

Thats exactly what I am referring to

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
M

mauricio florez

I have the same problem in my application, using WIN98 and Excel -
Office 2000.

Do you have some sample code to resolve the problem in VB.NET 2003?

Any clues?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top