DIAdem Help

Command: CreateExcelWorkbook

  • Updated2024-09-12
  • 2 minute(s) read

Display all  Hide all

Command: CreateExcelWorkbook

Creates a new Excel workbook or opens an existing Excel file. Excel does not need to be installed on your computer.

Set ReturnValue = CreateExcelWorkbook([ExcelFileName])

Input Parameters

[ExcelFileName] Specifies the Excel file that DIAdem opens. If you do not specify an Excel file, the command creates an Excel workbook with an empty worksheet named Sheet1.

Return Parameters

ReturnValue The return value is a Workbook object type. The Workbook object corresponds to an Excel workbook.

If you change the value of cells using the Workbook object, DIAdem does not refresh the values of the cells that reference these cells using a formula, for example.

The following example creates an Excel workbook, fills the first worksheet with random values, and highlights the cells containing the value 47 with a red background:

VBScriptPython

 

Dim iRow, jCol, oMyWorkbook, oMySheet, oMyCell
Set oMyWorkbook = CreateExcelWorkbook()
Set oMySheet = oMyWorkbook.Worksheets(1)
For iRow = 1 to 1000
  For jCol = 1 to 20
    Set oMyCell = oMySheet.Cells(iRow, jCol)
    oMyCell.Value = Round(Random(100))
    IF oMyCell.Value = 47 THEN oMyCell.Interior.Color = RGB(255, 0, 0)
  Next
Next
Call oMyWorkbook.SaveAs(DataWritePath & "Test.xlsx")