Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. Dim oExcel As Object
  2. Dim db As DAO.Database
  3. Dim rs As DAO.Recordset
  4. Dim CurrentColumn As Integer
  5.  
  6. 'Make a new instance of Excel
  7. Set oExcel = CreateObject("Excel.Application")
  8.  
  9. 'Have that instance open your workbook
  10. oExcel.Open("YourWorkBookName")
  11.  
  12. 'Open the database
  13. Set db = CurrentDb
  14. 'Create a SQL result from a SQL string to pull data from your database
  15. Set rs = db.OpenRecordset(YourSQLString)
  16.  
  17. 'Assign the value of a field in your SQL output to a cell
  18.  
  19. oExcel.Workbook("YourWorkBookName").Sheets("YourSheetName").Cell(YourCellRow, YourCellColumn") = rs.("FieldName")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement