PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

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

 
 
xhenxhe
Guest
Posts: n/a
 
      22nd Jul 2004
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


 
Reply With Quote
 
 
 
 
xhenxhe
Guest
Posts: n/a
 
      22nd Jul 2004
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" <(E-Mail Removed)> wrote in message
news:FCB64BE8-2427-483C-B4C7-(E-Mail Removed)...
> 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
> >
> >
> >



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      23rd Jul 2004
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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Object reference not set to an instance of an object" Weird thing happens with reference a link nguyentrongkha@gmail.com Microsoft ASP .NET 1 20th Sep 2007 10:46 PM
Error "object reference not set to instance of an object" when trying to set datasource property of a bound column in datagrid control Martin Widmer Microsoft VB .NET 0 23rd Jan 2006 10:24 AM
Activating an open instance of Word without opening a new instance Larry Microsoft Word Document Management 8 12th Nov 2003 06:05 AM
Object Reference Not Set to an Instance of an Object JC Microsoft Dot NET Framework 1 25th Sep 2003 07:44 PM
Object reference not set to an instance of an object- Dianna K Microsoft Dot NET Framework 2 17th Aug 2003 01:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:24 PM.