473,769 Members | 6,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Applicati on
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Try
xlApp = CType(CreateObj ect("Excel.Appl ication"), Excel.Applicati on)
Catch ex As Exception
MsgBox("Could not create Excel Application Object: " & ex.Message,
MsgBoxStyle.Cri tical, Title)
Exit Sub
End Try

Try
xlBook = CType(xlApp.Wor kbooks.Open(txt CommonTemplate. Text),
Excel.Workbook)
Catch ex As Exception
MsgBox("Could not create instance of Excel Workbook: " & ex.Message,
MsgBoxStyle.Cri tical, Title)
Exit Sub
End Try

Try
xlSheet = CType(xlBook.Wo rksheets(1), Excel.Worksheet )
Catch ex As Exception
MsgBox("Could not create instance of an Excel Worksheet: " & ex.Message,
MsgBoxStyle.Cri tical, 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 15327
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*****@discus sions.microsoft .com> wrote in message
news:FC******** *************** ***********@mic rosoft.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.Applicati on
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Try
xlApp = CType(CreateObj ect("Excel.Appl ication"), Excel.Applicati on)
Catch ex As Exception
MsgBox("Could not create Excel Application Object: " & ex.Message,
MsgBoxStyle.Cri tical, Title)
Exit Sub
End Try

Try
xlBook = CType(xlApp.Wor kbooks.Open(txt CommonTemplate. Text),
Excel.Workbook)
Catch ex As Exception
MsgBox("Could not create instance of Excel Workbook: " & ex.Message,
MsgBoxStyle.Cri tical, Title)
Exit Sub
End Try

Try
xlSheet = CType(xlBook.Wo rksheets(1), Excel.Worksheet )
Catch ex As Exception
MsgBox("Could not create instance of an Excel Worksheet: " & ex.Message, MsgBoxStyle.Cri tical, 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.Activat e

--
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.Applicati on
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Try
xlApp = CType(CreateObj ect("Excel.Appl ication"), Excel.Applicati on)
Catch ex As Exception
MsgBox("Could not create Excel Application Object: " & ex.Message,
MsgBoxStyle.Cri tical, Title)
Exit Sub
End Try

Try
xlBook = CType(xlApp.Wor kbooks.Open(txt CommonTemplate. Text),
Excel.Workbook)
Catch ex As Exception
MsgBox("Could not create instance of Excel Workbook: " & ex.Message,
MsgBoxStyle.Cri tical, Title)
Exit Sub
End Try

Try
xlSheet = CType(xlBook.Wo rksheets(1), Excel.Worksheet )
Catch ex As Exception
MsgBox("Could not create instance of an Excel Worksheet: " & ex.Message,
MsgBoxStyle.Cri tical, 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
8878
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 know how to build a Keys for this method in C# and how to pass this arguments in this method. Any example howto use this method would be nice. Thanks, Bart
3
1604
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 once a while after runing the program. Anyone know what's the peoblem? Thankx. -- Message posted via http://www.dotnetmonster.com
2
8874
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
1722
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
3032
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 Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet oXL = GetObject(, "Excel.Application") oWB = oXL.ActiveWorkbook oSheet = oWB.ActiveSheet
0
3039
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 cells in the object based on there new values. How do I do this? I've done this before with VBA scripts in excel using the cell.Interior.ColorIndex property, but it definitely doesn't work with this object. Any help would be much appreciated. I've...
16
2704
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 System.Collections.Generic.List<frmMain.sDBTest> LoadTestSet(string TestSetFile, System.Collections.Generic.List<frmMain.sDBTestDBviewList)
3
7176
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 application creates an Excel file (MyTestFile.XLS) just fine per the code submitted here. This code closes the Excel file created and close the Excel application, leaving the Access app open. Then I close Access. After Access is closed, I go to the task...
0
1609
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 xlSheets As Excel.Sheets Dim xlSheet As Excel.Worksheet xlApp = New Excel.Application
1
1383
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: objExcel.Workbooks.Open(Page.MapPath("reports\BLCost.xls")) could be the culprit since the Open method returns a reference to a Workbook object that you haven't assigned a variable to. Since you have no variable to explicitly use to destroy the...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.