error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
Go Back  Xtreme Visual Basic Talk > > > error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export


Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2008, 12:48 PM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export


Hi!

I am getting the following error:

error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when exporting to Excel from VB 2008

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x8002000B): Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
at Microsoft.Office.Interop.Excel.Sheets.get__Default(Object Index)
at Preview_Report_Generator.Form1.button4_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


This doesn't mean much to me since I fairly new at VB 2008 and in general.

I am attaching the code for the button that does the exporting.

Your help is greatly appreciated. It is a lottttt of code so your time is also apprecited.

Thanks for the help in advanced!

Tammy
Attached Files
File Type: txt button4 export to excel.txt (64.4 KB, 4 views)
Reply With Quote
  #2  
Old 09-03-2008, 12:59 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

It's impossible to say, that's a huge amount of code. The error message suggests that it is failing at the call to "Microsoft.Office.Interop.Excel.Sheets.get__Default(Object Index)", which is essentially the default Workbook.Worksheets(<Index>) property. The first line that shows this in your code is:

Code:
xlapp.Workbooks(1).Worksheets("Sheet1")
But you have this kind of thing at a number of places. You should run it from within Visual Studio (uncompiled) so that you can see on which line the error occurs.

Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #3  
Old 09-03-2008, 01:10 PM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default

Mike,

The problem is that when I run it on my development machine the whole code and the application itself works perfect.

But when I install the application in another machine is when I get the error message.

Any ideas are welcome.

Thanks


Tammy
Reply With Quote
  #4  
Old 09-03-2008, 02:09 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hi Tammy,

Ok, your issue, then is deployment, which is something I have extremely little experience with, I'm afraid.

I can only cover the basics really. What version of Excel are you targeting via your project references? Excel 2003? 2007? What version is installed on the machine that is failing?
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #5  
Old 09-03-2008, 02:28 PM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default

Mike,

Thank you so much for following up with me.

in development machine i have excel 2003 version 11.8220.8202 SP3.


in client machine I have also excel 2003 version 11.8220.8202 SP3.



office.dll in my application shows to be version 11.0.0.0. in application folder after installing the version is 11.0.8161.0


I checked the dlls from another application that i created and that also exports diff data and the dll's are the same versions. The other application works fine in the client machine.

I have spent over 2 weeks now trying to fix this and seem to have hit a brick wall here.

Do you know what else I can do?

Thanks a lot!

Tammy
Reply With Quote
  #6  
Old 09-03-2008, 02:42 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

No, I really don't I'm afraid.

I do find it interesting, though, that the code seems to get pretty far before failing. So a lot of the code would seem to be ok. Strange.

If I had this situation, I would make a minimalist project that did almost nothing. Opened Excel for starters, and that's it. Then try to deploy that.

If that works, then try adding some more functionality like opening a workbook and writing a value to a worksheet.

If that works, then just keep progressing untill you hit your wall again.

The point is that this approach should help you isolate what point is actually the problem.

I guess you could also lace your current code with msgboxes, or logging to a text file to see how far it gets. This might be less work, but I personally love the "minimalist test project" approach myself, and do this quite a bit with "open-ended" problems like this.

I wish I could suggest more, but this is how I would go about it.

Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #7  
Old 09-04-2008, 02:29 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Hi,

I think we need to see the code, at least the part that interact with the worksheet object, so we can suggest alternatives.

In addition, how does You deploy the solution?
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #8  
Old 09-04-2008, 06:44 AM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default

Thank you, Mike. I will probably have to end up doing that.

Dennis,

To deploy I am doing the right click solutions and add a new project, choose setup and then i ad dthe project output.

On the setup tab, I go to application folder and choose alwayscreate as true. I go to uder's program menu and also choose alwayscreate as true.

Maybe this will make it easier for you guys. Everything works fine in my machine when installing from .msi. When debugging prior to creating the msi I don't get any errors. When installing in the client machine, I made sure to install all prerequisites, they have office 2003 same version also installed (client machine is one of our other machines). This is very weird.

Everything works except when I click on export to excel which is button 4. It goes through a bit and then gives me the error message.


I am attaching all the code for my application as pdf and the application layout as bmp.


Thanks a lot for your help!

Tammy
Attached Images
File Type: bmp report application 942008.bmp (744.9 KB, 11 views)
Attached Files
File Type: pdf preview report generator 942008.pdf (169.9 KB, 13 views)
Reply With Quote
  #9  
Old 09-04-2008, 08:25 AM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default

guys,

I left only the part in which creates and formats and inserts the data in the first sheet..i.e sheet1. that works fine in the client computer.

I noticed that when it created the workbook in the client computer, it only inserted 3 sheets instead of 6. This seems to be the problem, even though in my computer it inserts 6 sheets. Can anyone explain to me the reason for this?

And how can I create the workbook with 6 sheets explicitly to overcome this problem?

Thanks a lot!

Tammy
Reply With Quote
  #10  
Old 09-04-2008, 09:27 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Tammy,

That's probably the reason why the solution throw an exception.

The default number of worksheets is controled via the command Tools | Options... in Excel. In the dialog You find it under the General Tab.

Quote:
And how can I create the workbook with 6 sheets explicitly to overcome this problem?
I assume You create a new workbook on the targeting computers so:
1) grab the number of worksheets in the created workbook.
2) add the required number of worksheets.

But if You only work with one worksheet then why not just:
1) Add one worksheet to the created workbook and name it and
2) then refer to this named worksheet in the code.

Let's know the current situation You have.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #11  
Old 09-04-2008, 11:33 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Ah, just when I thought this was going to be one of those crazy deployment problems that only Dennis could solve... Well, I guess it sort of was. Good pickup guys.

I agree with Dennis: use Workbook.Worksheets.Count to find out the current number of worksheets and then call Workbook.Worksheets.Add() a few more times to get the desired number of worksheets.

Don't change the default to 6 for the user -- you don't want to be changing this environment for them. Worse, they might find it annoying, change it back, and then your code would start crashing again.
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #12  
Old 09-04-2008, 12:38 PM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default

Dennis,

I need 6 sheets in the workbook.

I went to options and changed the number of sheets in excel and now it works perfect.

Thank you so much for your help!

Tammy

Thank you Mike too!!!!
Reply With Quote
  #13  
Old 09-05-2008, 06:04 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline
Out Of Office

Retired Moderator
* Expert *
 
Join Date: Mar 2005
Location: London, UK
Posts: 3,402
Default

Hi Tammy,

Like Dennis and Mike explained, that is not the correct way to solve this. Different users will have a different default number of worksheets. You should programmatically ensure that there are 6 worksheets and dynamically add to the collection via code as necessary. If you don't do it this way, your code will not be robust and will be prone to errors.

HTH
Colin
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
 
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
error invalid index (exception from hresult: 0X8002000B(DISP_E_BADINDEX)) when export
 
-->