RazerWriter Posted June 28, 2003 Posted June 28, 2003 "server has thrown an exception" at this line of code: exExcel.Workbooks.Open(strFilename) what the heck is wrong!!! Quote
*Experts* Volte Posted June 28, 2003 *Experts* Posted June 28, 2003 Are you positive the filename exists? Perhaps you should post some more related code. Quote
RazerWriter Posted June 28, 2003 Author Posted June 28, 2003 Dim exExcel As New Excel.Application Dim exSheet As Excel.Worksheet exExcel.Workbooks.Open(strFilename) yes, the file exists, i have even tried "c:\test.xls". I am using the Excel 8.0 Objects Library [edit]Dont start multiple threads on the same question[/edit] Quote
Leaders dynamic_sysop Posted June 28, 2003 Leaders Posted June 28, 2003 i'm using 10.0 but this may help , i think you should try setting the excel sheet as the item thats opening the app , like this : Dim exExcel As New Excel.Application() Dim exSheet As Excel.Workbook Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click exSheet = exExcel.Workbooks.Open("C:\Book1.xls") MsgBox(exSheet.Sheets.Count) '///just to check the excel app did open End Sub Quote
RazerWriter Posted June 28, 2003 Author Posted June 28, 2003 ------------------------------------ Option Strict Off Public Class xlManager Public Shared xlApp As Object Public Shared xlBook As Object Public Shared xlSheet As Object End Class Quote
RazerWriter Posted June 28, 2003 Author Posted June 28, 2003 ------------------------------------ Option Strict Off Public Class xlManager Public Shared xlApp As Object Public Shared xlBook As Object Public Shared xlSheet As Object sub xlApp = CreateObject("Excel.Application") 'Late bind an instance of an Excel workbook. xlBook = xlApp.Workbooks.Add 'Late bind an instance of an Excel worksheet. xlSheet = xlBook.Worksheets(1) xlSheet.Activate() xlBook.SaveAs(strFilename) end sub End Class ------------------------------------ Apparently VB NET has a feature called "late-binding". Somehow that code made it work! Strange. Well, I had to go through tons of msdn articles to get it. Thank God it works and I can go on with my life :) Quote
Recommended Posts