Question VB.net control over XL spredsheet

Razzor

New member
Joined
Oct 11, 2011
Messages
1
Programming Experience
3-5
Hi Everyone,

New to forum have a question for you well informed people.
i am trying to read XL 2003 spreadsheets in to VB.net 2008 all is ok until i try to import a particular spreadsheet that has formatting an i then run into this error "Excel cannot access 'ECN Spreadsheet Samples'. The document may be read-only or encrypted."
Can anyone point me in the right direction i have included the code below?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim xlApp As Object
Dim xlWorkBook As Object
Dim xlWorkSheet As Object
Dim range As Object
Dim Obj As Object
Dim n As Integer




xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("C:\Users\John\Desktop\ECN\ECN Spreadsheet Samples" & fileArr(n))
xlWorkSheet = xlWorkBook.Worksheets("sheet1")


range = xlWorkSheet.UsedRange
For n = 1 To fileArr.Count - 1 'fileArr holds the filee names of all the spreadsheets
For rCnt = 1 To range.Rows.Count 'Rows
For cCnt = 1 To range.Columns.Count 'Columns
Obj = CType(range.Cells(rCnt, cCnt), Microsoft.Office.Interop.Excel.Range)
MsgBox(Obj.value)
Next
Next
Next
End Sub
End Class
 
Back
Top