bkourouma
asked on
Problem reading some excel files
Hello,
I am reading excel files as follow;
Dim oXL As excel.Application
Dim oBook As excel.Workbook
Dim oSheet As excel.Worksheet
'create app
oXL = CreateObject("Excel.Applic ation")
oXL.DisplayAlerts = False
'creat workbook
oBook = oXL.Workbooks.Open("C:\070 206_shb_rh _s05_activ ité_CG100. xls", Type.Missing, True, Type.Missing, Type.Missing, Type.Missing, False, Type.Missing, Type.Missing, Type.Missing, False, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
'selecting sheets/renaming sheets
oBook.Worksheets("BALANCE AGEE").Select()
oSheet = oBook.Worksheets("BALANCE AGEE")
Dim str As String = oSheet.Range("B6").Value
For some files its fine. But for others, I get an error at this line:
oBook.Worksheets("BALANCE AGEE").Select()
For the files I am having problems, I get a warning stating that the workbook contains external links. It asks whether it shoold update or ignore. No matter my choice i get:
[COMException (0x8002000b): Index non valide. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))]
Microsoft.Office.Interop.E xcel.Sheet s.get__Def ault(Objec t Index) +0
test2.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\BABA\Mes documents\Visual Studio 2005\sifca\test2.aspx.vb:2 7
System.Web.UI.Control.OnLo ad(EventAr gs e) +88
System.Web.UI.Control.Load Recursive( ) +74
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +3035
Can someone help me on this?
I am reading excel files as follow;
Dim oXL As excel.Application
Dim oBook As excel.Workbook
Dim oSheet As excel.Worksheet
'create app
oXL = CreateObject("Excel.Applic
oXL.DisplayAlerts = False
'creat workbook
oBook = oXL.Workbooks.Open("C:\070
'selecting sheets/renaming sheets
oBook.Worksheets("BALANCE AGEE").Select()
oSheet = oBook.Worksheets("BALANCE AGEE")
Dim str As String = oSheet.Range("B6").Value
For some files its fine. But for others, I get an error at this line:
oBook.Worksheets("BALANCE AGEE").Select()
For the files I am having problems, I get a warning stating that the workbook contains external links. It asks whether it shoold update or ignore. No matter my choice i get:
[COMException (0x8002000b): Index non valide. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))]
Microsoft.Office.Interop.E
test2.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\BABA\Mes documents\Visual Studio 2005\sifca\test2.aspx.vb:2
System.Web.UI.Control.OnLo
System.Web.UI.Control.Load
System.Web.UI.Page.Process
Can someone help me on this?
ASKER
ryancys,
I still get the error.
Also I need to make sure that annoying warning does not come up.
Thanks.
I still get the error.
Also I need to make sure that annoying warning does not come up.
Thanks.
Can you make sure every excel documents got a worksheet called as "BALANCE AGEE" ?
ASKER
Yes, it does. The document I am reading does have ."BALANCE AGEE"
As matter of fact, here is the actual doc http://www.allianceconsultants.net/070206_shb_rh_s05_activité_CG100.xls
Thanks for your time.
As matter of fact, here is the actual doc http://www.allianceconsultants.net/070206_shb_rh_s05_activité_CG100.xls
Thanks for your time.
ASKER
Thanks, the problem was indeed the name in the sheet contained empty string as in ."BALANCE AGEE ".
Is there a way to rename the sheet "BALANCE AGEE"?
Thanks
Is there a way to rename the sheet "BALANCE AGEE"?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I tried that but i was doing oSheet = oBook.Worksheets(0) for the first sheet. lol
oBook.Worksheets("BALANCE AGEE").Select()
can be omitted in your case here, what if you removed/remarked this line?