create worksheet,input data to excel worksheet cell and save it?

I had retrive data from database and I require to do more with the data. right now I need to put those data input a worksheet.
This is what I have down
private sub datatoexcel()
Dim excelo as object
Dim I as integer
set excelo = createobject("Excel.Sheet")

the problem is now I don't know how to input data into cell??do I use excelo.cell(x,y) = variable to input data or there is a eary way??and how do I save the the object into a xls file after I finish everything?

Thanks
c4marAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

avitalkCommented:
try looking into MSDN - Office Developmeant, they have some examples there.

you need to use objects from a library called :" Microsoft Excel 8.0 Object Library"
which you should add to the references of the project.
that would allow you to access excel objects.

inserting data into excel cells and saving the file would look like this ( I'm inserting random data ):

Private Sub DoExcel()
Dim AppExcel As Excel.Application
Dim Wb As Excel.Workbook
Dim WS As Excel.Worksheet
Dim I As Long, J As Long

Set AppExcel = CreateObject("Excel.Application")
Set Wb = AppExcel.Workbooks.Add
Set WS = Wb.ActiveSheet

With WS.Range("A1")
    For I = 1 To 10
        For J = 1 To 10
           .Offset(I - 1, J - 1) = I * J
            DoEvents
        Next
    Next
End With
Wb.SaveAs App.Path & "\multiple.xls"
AppExcel.Visible = True
Set WS = Nothing
Set Wb = Nothing
Set AppExcel = Nothing
End Sub

I hope this helps.
Avital
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
c4marAuthor Commented:
avitalk have been a great help on the application that I am doing, however I still not able to find helpful information on the MSDN. There still have a little problem to about save excel workbook, does anyone know how to do it???
Wb.SaveAs App.Path & "\multiple.xls" (seem like doesn't working, I have try .savetofile, .savefile, but all of them fail to achieve saving excel workbook)
0
avitalkCommented:
Hi again,

Wb.SaveAs App.Path & "\multiple.xls"
worked fine in my computer.

the method Wb.SaveAs as additional optional parameters.  try playing with them.

also, try setting an error handler to see if any error happens.

info Excel objects in MSDN can be found in the following URL:
http://msdn.microsoft.com/library/officedev/office97/ORKhtml/FULLTOC.htm

or just search about Excel Object.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.