473,396 Members | 1,764 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,396 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 7182
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.