Automate Excel from basic

vegaseat 0 Tallied Votes 151 Views Share

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.

' do some basic data manipulations with EXCEL using COM
' (you have to have the EXCEL program installed on your computer)
' needs BCX basic ver 5.05.05 or later, download package from:
' http://www.rjpcomputing.com/programming/bcx/devsuite.html
' COM credit goes to: Ljubisa Knezevic

BCX_SHOW_COM_ERRORS(TRUE)

dim app as Object
set app = CreateObject("Excel.Application")

app.workbooks.add
app.visible = true
app.ActiveSheet.Cells(1,1).Value = "BCX does Excel ..."
app.ActiveSheet.Cells(3,1).Value = 12.3
app.ActiveSheet.Cells(4,1).Value = 7.4
app.ActiveSheet.Cells(5,1).Value = "-----------"
app.ActiveSheet.Cells(6,1).Value = "=sum(a3:a4)"  ' sum it up

msgbox "Press OK to close Excel"
' close down Excel
Sleep(100)
app.activeworkbook.saved = true  ' fake it
app.quit
set app = Nothing
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.