473,405 Members | 2,354 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,405 software developers and data experts.

Problem with Excel, Invalid Cast Exception Error

vinci
62
Please help me out... i only have two weeks to do it...


here is my code:

Expand|Select|Wrap|Line Numbers
  1.         Dim ex As New Object
  2.         Dim wb As Excel.Workbook
  3.         Dim sheet As Excel.Worksheet
  4.  
  5.         'create xls file and save into the specific path
  6.         ex = CreateObject("Excel.Application")
  7.  
  8.         Dim wrkbook As Excel.Workbook
  9.         wrkbook = ex.Workbooks.Open("C:\Inetpub\wwwroot\WWReport\Maxim.xls")
  10.         sheet = wrkbook.Sheets(3)
  11.  
the error is in line 9... in the above snippet

my program should be generating an excel report. i have a template, and when i open the template (see code) the error occurs...

why is it occuring? i used late binding to create my Excel.Application Object...

this code works fine in office 2003, unfortunately, the company where im in is using office 2002, i am using either Microsoft excel object Library 10.0 or Microsoft.office.interop.excel.dll (which i downloaded from the internet "PIA") but either way, error still occurs wether i use excel object 10.0 or PIA.

Working with VB.Net 2003, Microsoft office 2002 (excel)

pls. help me out!

tnx a lot!

THE ERROR!!!

-------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 60: 'open the xls file after it has been saved
Line 61: Dim wrkbook As Excel.Workbook
Line 62: wrkbook = ex.Workbooks.Open("C:\Inetpub\wwwroot\WWReport\Max im.xls") ->this line is the source of the error
Line 63: sheet = wrkbook.Sheets(3)
Line 64:


Source File: C:\Inetpub\wwwroot\WWReport\GWHM.aspx.vb Line: 62

Stack Trace:


[InvalidCastException: Specified cast is not valid.]
WWReport.GWHM.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WWReport\GWHM.aspx.vb:62
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Aug 30 '07 #1
1 4408
vinci
62
just wanted to inform everyone that i already got the solution...

so ignore this thread! thanks!

what i did was, i declared all the variables as object (using the late binding method) and everything worked fine... how stupid of me to not immediately figure out the solution well in fact the soln is already in my hands...

Thank God!


TSDN Mabuhay!
Aug 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
1
by: Walter Andosen | last post by:
I have some trouble creating a Excel workbook. I get lots of Exceptions. For example I get System.Runtime.InteropServices.COMException (0x80028018): Old format or invalid type library. at...
2
by: Darren Clark | last post by:
I am having some troubles with Sessin varables dieing.. Basically ihave my own class structure called USER that once the user logs in i save it to a session var called Session = myUserObject; ...
3
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
1
by: Boomessh | last post by:
Hi, I am trying to open an existing excel workbook. It pops up an error stating that “Errors were detected in 1598.xls but Microsoft Office Excel was able to open the file by making the repairs...
0
by: Brano | last post by:
Hi all, I have a asp.net website that has been live for about 2 weeks now and there were no problems with it. I have got a new server that is Win 2003 IIS 6.0 I have moved my application onto...
0
by: Bill Fallon | last post by:
I am developing a VB.Net application with VS 2005 that opens an Excel workbook and populates the worksheet with data. I started developing the application with Office 2007 installed on my Vista...
2
by: John Heitmuller. | last post by:
Hi, I have a VB.Net application that I have recently upgraded from Visual Studio 2003 to Visual Studio 2005. The VB.Net app accesses Word and Excel. When I run the newly compiled VB.Net app on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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...

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.