Visual Basic 6 exporting info to Excel

I'm using VB6 and have some data, (some string labels with data, also some raw data that will eventually be graphed) and I'd like to export this to an excel spreadsheet. I'd like the operator to hit a button which somehow just transfers this data to an excel spreadsheet. Is this possible? Does anyone have a small sample chunk of code for setting it up, and running it? Do I use OLE? This is pretty urgent but I only have 95 points. Thanks
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.

Éric MoreauSenior .Net ConsultantCommented:
Start a new project, add a command button to the form and a reference to Excel. Finally paste this code:

Option Explicit

Private xl As Excel.Application

Private Sub Command1_Click()
Dim intI As Integer

    Set xl = New Excel.Application
    With xl
        .Visible = True
        With .ActiveWorkbook.ActiveSheet
            .Columns("A:A").ColumnWidth = 20
            .Columns("B:B").ColumnWidth = 5
            .Columns("C:C").ColumnWidth = 15
            .Columns("C:C").NumberFormat = "#,##0.00 $"
            For intI = 1 To 100
                .Range("A" & intI).Value = intI
                .Range("C" & intI).Formula = "=SUM(A" & intI & " * 25)"
            Next intI
            .Range("C102").Formula = "=SUM(C1:C100)"
        End With
    End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    xl.ActiveWorkbook.Close False
    Set xl = Nothing
End Sub

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
jeffreyscharpfAuthor Commented:
That's exactly what I needed to get started!


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
Microsoft Development

From novice to tech pro — start learning today.