This is an example of
Script BASIC creating an
Excel spreadsheet with some test data and saving the file.
IMPORT com.inc
filename = "C:\sb22\scriptledger\test.xlsx"
IF FileExists(filename) THEN
PRINT "File already exists deleting: ", filename,"\n"
DELETE filename
END IF
oExcelApp = VBNEW("Excel.Application")
IF oExcelApp = 0 THEN
PRINT "Failed to create Excel Object do you have it installed?"
GOTO Obj_Release
end if
' VBScript: Set ExcelWorkbook = ExcelApp.Workbooks.Add
oWorkBook = VBCALL(oExcelApp, "Workbooks", vbGet)
oExcelWorkbook = VBCALL(oWorkBook, "Add")
' VBScript: Set ExcelSheet = ExcelWorkbook.Worksheets(1)
oExcelSheet = VBCALL(oExcelWorkbook, "Worksheets", vbGet, 1)
FOR i = 0 TO 10
FOR j = 0 TO 10
' VBScript: ExcelSheet.Cells(i, j).Value = "test-" & i & "-" & j
oCell = VBCALL(oExcelSheet, "Cells", vbGet, i, j)
VBCALL oCell, "Value", vbLet, "test-" & i & "-" & j
VBREL oCell
NEXT
NEXT
' Save new workbook and exit
VBCALL oExcelWorkbook, "SaveAs", vbMethod, filename
VBCALL oExcelWorkbook, "Close"
VBCALL oExcelApp, "Quit"
Obj_Release:
VBREL oExcelSheet
VBREL oExcelWorkbook
VBREL oWorkBook
VBREL oExcelApp