I am trying to open an excel file using .NET's excel object. It was working fine before.. I dont know why it started giving me a COMException error recently.. I am trying to figure why but I cant.. My excel is not protected or locked.. But still it gives me the same error. This is what I coded:
Dim strcon As String
strcon = "PROVIDER = Microsoft.jet.OLEDB.4.0; Data Source = " & _
Me.txtTemplateFile.Text & "; Extended Properties = Excel 8.0 "
Dim olecon As OleDb.OleDbConnection
olecon = New OleDb.OleDbConnection(strcon)
Dim table As DataTable
Dim objxl As Excel.Application
objxl = New Excel.Application()
Dim wbxs As Excel.Workbooks
Dim wbxl As Excel.Workbook
Dim xl_file As String
xl_file = Me.txtTemplateFile.Text
wbxs = objxl.Workbooks
wbxl = wbxs.Add
wbxl = wbxs.Open(xl_file)
and this is the error it generates
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication2.exe
Additional information: Cannot access 'Lab_Data_Sheet.xls'.
Any comments or suggestions would be greatly appreciated.