473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

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
6 7176
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
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

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
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
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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: VBProgrammer | last post by:
I get the following error when I do an Excel.Workbooks.Open. This error occurs on some PCs but not others. The error and associated code are below. Thanks in advanc Error...
1
by: Benjamin | last post by:
I am making a Windows EXE (.NET Visual Basic Windows Application). I would like to make it possible to open Excel Worksheets from my EXE. This should work independent of Excel version on client...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
0
by: Dan | last post by:
I'm using VB .net to open an excel file for reading. Everything works great when running on a machine with Visual Studio .Net installed. However when I try to distribute the application I get...
3
by: Michael Kellogg | last post by:
My application works with Excel to put together spreadsheets for reporting purposes. It runs just fine on my box, but when I put it on another one, it bombs. Here is the relevant code: ...
13
by: chuckie_9497 | last post by:
hello all you gurus. I am struggling with releasing com objects. I have isolated the problem to the code below. Objects are released and the process ends until I use "int k = sheet.Count;" Then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.