By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,030 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,030 IT Pros & Developers. It's quick & easy.

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

P: n/a
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(MouseEventAr gs 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(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

"Chuck" <ch***@yeshcom.com> wrote in message
news:a4**************************@posting.google.c om...
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(MouseEventAr gs 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(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

Nov 21 '05 #2

P: n/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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

P: n/a

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

"chuck a" <no****@me.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4

P: n/a
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.

"One Handed Man ( OHM - Terry Burns )" wrote:

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

"chuck a" <no****@me.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 21 '05 #5

P: n/a
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

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
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.

"One Handed Man ( OHM - Terry Burns )" wrote:

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

"chuck a" <no****@me.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 21 '05 #6

P: n/a


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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.