BASIC Developer & Support Resources > VB (5/6/CE) Classic

Script BASIC Excel

(1/1)

John:
This is an example of Script BASIC creating an Excel spreadsheet with some test data and saving the file.




--- Code: Script BASIC ---IMPORT com.inc filename = "C:\sb22\scriptledger\test.xlsx" IF FileExists(filename) THEN  PRINT "File already exists deleting: ", filename,"\n"  DELETE filenameEND IF oExcelApp = VBNEW("Excel.Application") IF oExcelApp = 0 THEN  PRINT "Failed to create Excel Object do you have it installed?"  GOTO Obj_Releaseend if ' VBScript: Set ExcelWorkbook = ExcelApp.Workbooks.AddoWorkBook = 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  NEXTNEXT ' Save new workbook and exit VBCALL oExcelWorkbook, "SaveAs", vbMethod, filenameVBCALL oExcelWorkbook, "Close"VBCALL oExcelApp, "Quit" Obj_Release: VBREL oExcelSheetVBREL oExcelWorkbookVBREL oWorkBookVBREL oExcelApp 

Navigation

[0] Message Index

Go to full version