-
Hi guys, I know this has been answered here before 'cuz I have seen it here, but now I can't find it. Fitting, huh? Anyway, can someone give me an example on how to create an Excel spreadsheet from VB and copy values from a recordset into it? I would be very thankful!
Thanks
Andrew
-
Try something like this: (Replace the Dummy Data with your Recordset Data)..
Code:
Private Sub Command1_Click()
'Add a Reference to the Microsoft Excel Object Library via the "Project" Menu
Dim oApp As New Excel.Application
Dim oWorkbook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim iRow As Long
Dim iCol As Long
Set oWorkbook = oApp.Workbooks.Add
Set oSheet = oWorkbook.Sheets(1)
With oSheet
For iRow = 1 To 10
For iCol = 1 To 10
.Cells(iRow, iCol) = Rnd * 1000
Next
Next
.SaveAs "C:\NewSheet.xls"
End With
oWorkbook.Close
oApp.Quit
Set oSheet = Nothing
Set oWorkbook = Nothing
Set oApp = Nothing
End Sub