I wrote this code to open existing excel sheet,when i run the code, it opens an empty file. Can you please help me?
Here is the code.
________________________________________________________
Public Sub btmOpen_Click(sender As Object, e As EventArgs)
Dim ObjExcel As Object
Dim ObjWS As Object
Dim Report As Object
Dim Marshal As Object
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\NewUser.xls;Extended Properties= Excel 8.0;HDR=YES;"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
ObjExcel = CreateObject("Excel.Application")
ObjExcel.Visible = True
'Define o excel workbook
ObjExcel.Workbooks.Add()
ObjExcel.Workbooks.Open("NewUser.xls") <<< Here is the problem
Dim ObjW = ObjExcel.ActiveWorkbook
ObjWS = ObjExcel.Worksheets("Sheet1")
ObjWS.Cells(1, 1) = "Excel example"
ObjW.Save()
ObjExcel.Quit()
Marshal.ReleaseComObject(ObjW)
Marshal.ReleaseComObject(ObjExcel)
ObjExcel = Nothing
System.GC.Collect()
System.GC.Collect()
End Sub
____________________________________________________________
The error as following:
Exception Details: System.Runtime.InteropServices.COMException: 'NewUser.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.
Orange.Obvious question: does C:\Inetpub\wwwroot\NewUser.xls exist?
Check it even if you know it's there.
I checked it before i posted my problem...
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment