How to take data from a VB database application and place it into an Excel spreadsheet
Posted on August 10, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 'MS Office - How to take data from a VB database application and place it into an Excel spreadsheet Private Sub Excel_Spreadsheet(rst As Recordset) 'Declare all Excel objects Dim xlApp As Excel.Application Dim xlWB As Excel.Workbook Dim xlWS As Excel.Worksheet Set xlApp = New Excel.Application Set xlWB = xlApp.Workbooks.Add Set xlWS = xlWB.Worksheets.Add 'Fill cells using recordset xlWS.Cells(1, 1).Value = rst("Field1") xlWS.Cells(2, 1).Value = rst("Field2") 'save spreadsheet xlWS.SaveAS "mysheet.xls" xlApp.Quit 'Free memory Set xlWS = Nothing Set xlWB = Nothing Set xlApp = Nothing End Sub |