Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Write to Excel?...

Status
Not open for further replies.

BrokkenStik

Programmer
Jul 12, 2001
10
US
I would like to generate database reports using MS Excel. This would involve populating a .xls file, and then bringing it up on the desktop. So my questions are as follows:

1) How do I connect to Excel from my VB 5.0 application? The help files mention IISAMs, but I couldn't find any examples.

2) Once I'm in, how do I access individual cells? Once again, the help files mention something on this subject, but I've not had sucess yet.

3) How do I bring Excel to the desktop? I'm assuming the file has been populated, but at this point, I would like to use Excel's full functionality such as print, save as, etc.

Thank you,

'Stik
 
Do a search in the VB 5&6 forum. This question has been addressed several times. There should be plenty of sample code there.

I would suggest using CreateObject to start Excel. Include the Excel Object Library in your Project References. Then, you have complete control over the Excel session.
 
Did a search in the VB 5 & 6 forum, but didn't find anything that applied to my problem. However, thanks to "VB & VBA in a Nutshell" (Paul Lomax), the solution is as follows....

Dim xlApp as Excel.Application
Dim xlWorkbook as Excel.Workbook
Dim xlWorksheet as Excel.Worksheet

' Make the connection....
Set xlApp = New Excel.Application
Set xlWorkbook = xlApp.Workbooks.Add
Set xlWorksheet = xlWorkbook.Worksheets.Add

' Address individual cells....
With xlWorksheet
.Cells(1, 1) = value
.
.
.
End With

' Close the connections....
xlApp.Quit
xlWorksheet = Nothing
xlWorkbook = Nothing
xlApp = Nothing

This automation provides the full functionality of Excel when the application is made visible.

Regards,

'Stik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top