I know there are lots of documents out there on how to do this, my problem is I dont understand. I'm using VB6.0.
Say I have an array which is only a list of numbers, its a single row, so it's easy enough. I suppose i see two option of doing this. I can either load the CSV file that the user can save, or the more prefered option i'd like is that when a user clicks a button, an excel sheet becomes visible and puts the array into individual cells.
How would i go about doing this? Please tell me in details as I can't seem to make sense of the documents. If you suggest the loading CSV way, is there a way to remember the commondialog filename so the user doesnt need to search for the csv? Any help is highly appreciated.
Ok.. your question is a common one, and I'll try to answer it as best I can. In order to do what you are wanting to do, you have to ensure that Excel is present on your target machine. After doing that, Go to Project -> References, and scroll down until you see the Microsoft Excel 9x/10x library. Select that library for a new reference. Then, you must create an object reference, so you can have
Code:
dim NewExcel as new Excel.Application
The NewExcel object will have many methods, one of which is the "ActiveWorksheet" (I believe that's its nomenclature). Within that method, there are other methods such as cell, row, column, blah blah blah. What you have is essentially a 2 dimensional array. So, just like an array, you can declare two counter variables, say - i and j, and use them to step through each row, one cell at a time. Say that i represents the row number, and j represents the cell number, then the selected cell within which you are currently working would be...
Code:
dim i as integer, j as integer
for i = 0 to SomeLimit
for j = 0 to AnotherLimit
NewExcel.ActiveWorksheet.cells(i,j) = cstr(somevalue)
next j
next i
You can step though them by incrementing the values by one, and in your inner loop, assigning the values that you want in each cell.
There are other methods that you would want to use as well, such as NewExcel.ActiveWorksheet.visible = true/false, which would cause your excel worksheet to either show or not. All of this can be called from a button click to accomplish your purpose. Does this help at all?
Was this answer helpful ?
Yes No
Your help is greatly appreciated, so much thanks. I'm not quite sure that, that worked though as it told me, 'run time error '483. Object doesnt support this property or method.'
Your clarification makes this seem do able however. I always thought that they would make something used that often fairly easy, and it appears as so. I'll research my prob from other threads now that I see what the basis of it is.
Was this answer helpful ?
Yes No
sorry, I was in a hurry when I wrote that...
Code:
Private Sub Form_Load()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
xlSheet.Cells(1, 1) = CStr("Hello")
End Sub
Was this answer helpful ?
Yes No