DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   qbasic (http://www.daniweb.com/code/qbasic.html)
-   -   Automate Excel from basic (http://www.daniweb.com/code/snippet142.html)

vegaseat qbasic syntax
Jan 6th, 2005
Another look at BCX basic. Here we use COM support to manipulate Excel. In other words, from within the basic code we are entering a few numbers into the Excel spreadsheet and add them up. Of course you can do much more powerful stuff. With COM support you can also access Word and the Internet Explorer from your basic program.

  1. ' do some basic data manipulations with EXCEL using COM
  2. ' (you have to have the EXCEL program installed on your computer)
  3. ' needs BCX basic ver 5.05.05 or later, download package from:
  4. ' http://www.rjpcomputing.com/programming/bcx/devsuite.html
  5. ' COM credit goes to: Ljubisa Knezevic
  6.  
  7. BCX_SHOW_COM_ERRORS(TRUE)
  8.  
  9. DIM app AS Object
  10. set app = CreateObject("Excel.Application")
  11.  
  12. app.workbooks.add
  13. app.visible = true
  14. app.ActiveSheet.Cells(1,1).Value = "BCX does Excel ..."
  15. app.ActiveSheet.Cells(3,1).Value = 12.3
  16. app.ActiveSheet.Cells(4,1).Value = 7.4
  17. app.ActiveSheet.Cells(5,1).Value = "-----------"
  18. app.ActiveSheet.Cells(6,1).Value = "=sum(a3:a4)" ' sum it up
  19.  
  20. msgbox "Press OK to close Excel"
  21. ' close down Excel
  22. SLEEP(100)
  23. app.activeworkbook.saved = true ' fake it
  24. app.quit
  25. set app = Nothing
  26.