473,396 Members | 1,846 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.

Opening Excel Worksheet - "Object reference not set to an instance of an object."

I don't some Excel automation. I've created a program that opens and Excel
template and inputs information to it. It runs great on my machine. When I
build and deploy I have a user that keep getting the error message: "Object
reference not set to an instance of an object."

Here is the code that generates the message:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Try
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
Catch ex As Exception
MsgBox("Could not create Excel Application Object: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

Try
xlBook = CType(xlApp.Workbooks.Open(txtCommonTemplate.Text) ,
Excel.Workbook)
Catch ex As Exception
MsgBox("Could not create instance of Excel Workbook: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

Try
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
Catch ex As Exception
MsgBox("Could not create instance of an Excel Worksheet: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

====

It is the second Try/Catch that displays the message - trying to open the
worksheet.

I've tried different variants of this code (new instead of ctype) which all
product the same results.

The user having problems is running office 2000. I'm using Office 2002. I'm
assuming this is the problem. Does anyone have a solution (other than me
downgrading or the user upgrading)?

Thanks,
Dustin

--
Dustin
--
http://www.LDSPDA.com
http://www.Shiblon.com
Nov 20 '05 #1
2 15303
Hi Brian, I had just read many of your posts here
(http://www.devdex.com/vb/message.asp...4362847&page=2) before posting
this message...

It appears I'm using version 10. Where would I obtain other versions?

Thanks,
D

--
Dustin
--
http://www.LDSPDA.com
http://www.Shiblon.com

"BrianDH" <Br*****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
what version of Excel & Office dll LIB's are you using? 9, 11 ?
you may need to add addtional refferences to other objects to run both 200 & 2002.
B

"xhenxhe" wrote:
I don't some Excel automation. I've created a program that opens and Excel template and inputs information to it. It runs great on my machine. When I build and deploy I have a user that keep getting the error message: "Object reference not set to an instance of an object."

Here is the code that generates the message:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Try
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
Catch ex As Exception
MsgBox("Could not create Excel Application Object: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

Try
xlBook = CType(xlApp.Workbooks.Open(txtCommonTemplate.Text) ,
Excel.Workbook)
Catch ex As Exception
MsgBox("Could not create instance of Excel Workbook: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

Try
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
Catch ex As Exception
MsgBox("Could not create instance of an Excel Worksheet: " & ex.Message, MsgBoxStyle.Critical, Title)
Exit Sub
End Try

====

It is the second Try/Catch that displays the message - trying to open the worksheet.

I've tried different variants of this code (new instead of ctype) which all product the same results.

The user having problems is running office 2000. I'm using Office 2002. I'm assuming this is the problem. Does anyone have a solution (other than me
downgrading or the user upgrading)?

Thanks,
Dustin

--
Dustin
--
http://www.LDSPDA.com
http://www.Shiblon.com

Nov 20 '05 #2
For some statements to work with Excel, you have to make the worksheet active;

xlsheet.Activate

--
Dennis in Houston
"xhenxhe" wrote:
I don't some Excel automation. I've created a program that opens and Excel
template and inputs information to it. It runs great on my machine. When I
build and deploy I have a user that keep getting the error message: "Object
reference not set to an instance of an object."

Here is the code that generates the message:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Try
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
Catch ex As Exception
MsgBox("Could not create Excel Application Object: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

Try
xlBook = CType(xlApp.Workbooks.Open(txtCommonTemplate.Text) ,
Excel.Workbook)
Catch ex As Exception
MsgBox("Could not create instance of Excel Workbook: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

Try
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
Catch ex As Exception
MsgBox("Could not create instance of an Excel Worksheet: " & ex.Message,
MsgBoxStyle.Critical, Title)
Exit Sub
End Try

====

It is the second Try/Catch that displays the message - trying to open the
worksheet.

I've tried different variants of this code (new instead of ctype) which all
product the same results.

The user having problems is running office 2000. I'm using Office 2002. I'm
assuming this is the problem. Does anyone have a solution (other than me
downgrading or the user upgrading)?

Thanks,
Dustin

--
Dustin
--
http://www.LDSPDA.com
http://www.Shiblon.com

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bart Filipski | last post by:
Hello, Does anyone know how looks the syntax of SORT method in Excel object ( i mean precisely in Excel.Workbook.Worksheet.Cells.Sort(...) ) I have tryied in VBA and it works great, but I don't...
3
by: yaya via DotNetMonster.com | last post by:
Hi all, Im using Microsoft Excel 11.0 Object Library as my program reference to create an Excel object, everything works fine but I notice that a process named EXCEL.EXE will run on the backgraound...
2
by: al | last post by:
Greetings, I'm wondering if Excel object CopyFromRecordset is still supported in VB.NET?? If not, what is the alternative, looping through dataset???? MTIA, Grawsha
2
by: 7777777.chen | last post by:
Hi, In C++ project, I need open excel file and write data to it. Can someone give me some intrusction? Thanks, Sherry
3
by: Ian Dunn | last post by:
I'm simply trying to access an instance of Excel that has been opened manually by the user in order to put a few values in the existing sheet. Here's the code I've tried: Dim oXL As...
0
by: NDK | last post by:
Ok so I have an html page with an embedded excel object. I load some information into the object from a spreadsheet. (works perfectly) I would like to be able to change the background of a few...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
3
by: rlntemp-gng | last post by:
RE: Access 2003/Excel 2003 Problem: After I close the Access application completely, I go out to the Task Manager and there is an Excel.exe object still sitting out there. My Access...
0
by: =?Utf-8?B?TW9udGU=?= | last post by:
I am using VB.NET to open and read info from Excel spreadsheets using code similar to this: Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlBooks As Excel.Workbooks Dim...
1
by: Scott M. | last post by:
Many methods return objects when they are called. With Excel these objects are placed in memory and must be destroyed via ReleaseComObject as you have done with your NAR method, but the line: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.