Excel not function in .Net

davidDSB
08-12-2004, 04:57 AM
My version of VB .Net is 2003 and excle libray is 11.0 (Excel 2003)

Imports Excel
Public Class Form1
Inherits System.Windows.Forms.Form
Dim eX As Excel.Application
Dim wb As Excel.Workbook
Dim ws1 As Excel.Worksheet
Dim ws2 As Excel.Worksheet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'When I use this two next lines into the "If"(i remove the if for this) an error occur on the
'second line. See the message:
'COMException]: {System.Runtime.InteropServices.COMException}
'Message: "Library of format is old or invalid type."
'Source: "Interop.Excel"
If 1 = 2 Then
eX = GetObject(, "Excel.Application")
eX.DisplayAlerts = False
wb = eX.Workbooks.Open("C:\Administrator3_0\BdDados\Relatórios\Relatórios.xls")
End If
'=================================================
'using These four next lines no error occur
wb = GetObject("C:\Administrator3_0\BdDados\Relatórios\Relatórios.xls")
eX = wb.Application
eX.Visible = True
wb.Windows(1).Visible = True
wb.PrintPreview()
'===============================================
'When the program go on the next line, was occuring the err CAN'T CONVERT TO INTERFACE WORKSHEET
'I don't know how, but that error stoped to occur sudenly.
'My version of VB.Net is 2003 and Excel library is 11.0
'See the excepetion error message:
'[System.Runtime.InteropServices.COMException]: {System.Runtime.InteropServices.COMException}
'Message: "Exception from HRESULT: 0x800A03EC."
'TargetSite: {System.Reflection.RuntimeMethodInfo}
ws1 = CType(wb.Worksheets(1), Excel.Worksheet)
ws2 = CType(wb.Worksheets(2), Excel.Worksheet)
'On the next line the err occur
ws1.Cells(1, 1).value = "IIIIIII"
'In the next line occur the same error initial
'Message: "Library of format is old or invalid type."
ws2.Activate()
Catch es As Exception
MessageBox.Show(es.ToString & " -- " & es.TargetSite.ToString)
End Try
End Sub
End Class

Mike Rosenblum
08-12-2004, 07:32 AM
I don' really see anything wrong with your code, unfortunately. It would seem to be some kind of installation issue/problem. I'll try to help you narrow this down a bit, but I'm not that hopeful... :(

Oh, it won't affect how your code runs, but most people use 'ex' for their Exception handler. I realize that you have used 'es', which is fine, but, well, it drives me a bit crazy to look at it this way! So, if you don't mind, I'm going to use different variable names, ok?

Anyway, let's take the first 3 lines:eX = GetObject(, "Excel.Application")
eX.DisplayAlerts = False
wb = eX.Workbooks.Open("C:\Administrator3_0\BdDados\Relatórios\Relatórios.xls") Let's just try to take baby steps for now; can you run the following code?Dim oXL as Excel.Application
Dim oWB as Excel.Workbook
Dim oWS as Excel.Worksheet

oXL = New Excel.Application
oWB = oXL.Workbooks.Add
oWS = CType(oWB.Worksheets(1), Excel.Worksheet)
MessageBox.Show(oWS) The code above is:

(1) Creating a New Excel.Application instead of using GetObject().
(2) Using Workbooks.Add() instead of opening a specific Workbook.

If we can get past this, then maybe we can add complexity bit by bit?

Hope, hope...
-- Mike

davidDSB
08-12-2004, 04:25 PM
I search on internet and see that exist very person with the same question. I solved my situation how exposed below:
Initial situation:
Vb .Net 2003 - English
Windows Xp - Portugues Brasil
Office xp 2003 - English

Solved situation:
Vb .Net 2003 - English
Windows Xp - Portugues Brasil
Office xp 2003 - Portugues Brasil

:D

Mike Rosenblum
08-12-2004, 05:14 PM
Wow!? Thanks David! Who knew right? :huh:

Thanks so much for sharing this solution with us. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum