I am using Excel interop in my VB.NET program. My problem is that I can't seem to figure out how to write to Excel *and* define the Range using numbers.

Alright, so I have objects being created depending on the file that the user opens. So there could be 100 objects or there could be none. Now each object has an array of values, and these arrays contain nearly 15000 elements. So here is what I want to do but I can't figure out how to escape using the LetterNumber:LetterNumber combination.

For every object I want a new column to be occupied and for every element in the objects array I want the row to be occupied. I figured the easiest way to do this was using a for loop but, again, I can't use numbers.

For columns = 0 to NumberOfObjects
       For rows = 0 to NumberInArray
              Cell(0,0).Value = myObjectsCollection(column).Array(rows)
       Next
    Next

Hi Tweed. Difficult to give a decent answer without knowing more about you objects, but in rough pseudoish code, maybe this will help:

Dim column as integer = 0
Dim row as integer =0
Dim obj as myObject

For column = 1 to myObjectsCollection.Count
	myObject = myObjectCollection(Column)
	For row = 1 to myObject.Array.upperbound(0)+1 
             Cell(column,row).Value = myObject.Array(row-1)
       Next
    Next

All the usual stuff about 1 based collections and zero based arrays. Also, probably have to check array length for each object/column. Good luck.

I'm using the same Excel Interops..but when i run it on local machine or debug at my local or host server it works exactly as required,but when being run from server it give error regarding Active X Components. What should be the reason and how can i resolve it. Please help me out
Thanks..

Hi vvashishta. It would have been better to start your own thread for this issue. Anyway, in order for someone to give you a good answer, it would help to give more information. What is your set up? How are you intending to deploy your application? Web/windows/lan? Either way, a good guess would be that Excel is not installed on the machine where you are trying to run your deployed application - or perhaps there are some Excel versioning issues? When you referenced Excel did you select "Microsoft Excel 9.0 Object Library" Or was it version an earlier or later version? And is the same version installed on your target machine? If not you will probably get a message like "Cannot create ActiveX object... " etc Just a guess

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.