Manipulating Excel files from VB

i have an excel file and i have to manipulate it from vb. i need to export report information to excel....

is about OLE?
atheAsked:
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.

DabasCommented:
Add MS Excel to your Project -> References

Try to view a few examples from help to get ideas on how to use an Excel object in VB

Dabas
0
atheAuthor Commented:
where do i find  a MS Excel object??
0
DabasCommented:
First in Project -> References tick the checkbox next to Microsoft Excel Project Library

Then in your project you can type something like:

Dim xl as Excel.Application

Or, press F2 and have a look at the object browser for Excel

Dabas
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

atheAuthor Commented:
i have had a look at the browser for excel but i dont understand how to use it....

i have an excel file and i have to modify it with my program data, how can i manipulate this? where i can learn how to access to the columns and rows?
0
DabasCommented:
Assume you want to fill cells A1, B1, A2, B2 with the numbers 3, 4,5 and 6, this is what the code would look like:

Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Public Sub Command1_Click

   Set xl = New Excel.Application
   Set wb = xl.Workbooks.Open(txtFileName) 'Assuming you have a TextBox that holds the file you want to open.
   Set ws = wb.Worksheets(1) 'Point to the first worksheet

   ws.Cells(1, 1) = 1 'A1
   ws.Cells(1, 2) = 2 'A2
   ws.Cells(2, 1) = 3 'B1
   ws.Cells(2, 2) = 4 'B2

End Sub

I hope this can get you started!

Dabas
0
atheAuthor Commented:
i think it should work!! thanks!!
i'm going to test it and i'll come back later to give you the points!! ;)
0
atheAuthor Commented:
it worked!! one last thing.... if i don't want to save changes in the same file opened, what i have to do?
0
DabasCommented:
athe:

Glad it worked!

Try:

xl.DisplayAlerts = False
xl.Quit

Dabas
0
atheAuthor Commented:
but, how do i save changes in another file? the point is to have a pattern file to get the structure, but saving changes in another file.... you know what i mean? is that what you have told me, i think i haven't understood.... :S
0
DabasCommented:
No, I did not understand you. I thought you wanted to exit Excel without it asking you to save.

What you want gets achieved with:

wb.SaveAs "New File Name"
0
DabasCommented:
You might be interested in the following link, as it is related to this one

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20537347.html

Dabas
0
atheAuthor Commented:
when i finish my working with with excel application opened, i close everything but an excel proccess continue execution and i have to finish with CTRL-ALT-SUPR....

i think i need to write some code telling vb to close excel....

i write this code and then, i work with excel file cells....

    Set xl = New Excel.Application
    Set wb = xl.Workbooks.Open(App.Path & "\Envio.xls")
    Set ws = wb.Worksheets(1)

what do i have to write exactly to finish excel and to save in another file (not envios.xls)?
0
DabasCommented:

wb.SaveAs "NewName.xls"
xl.Quit

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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.