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
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