Object: Worksheet
- Updated2024-09-12
- 1 minute(s) read
Excel > Objects > Workbook > Worksheets > Object: Worksheet
Object: Worksheet
The Worksheet object corresponds to an Excel worksheet.
The following example creates an Excel workbook and outputs the name of the first worksheet:
| VBScript | Python |
Dim oMyWorkbook, oMySheet Set oMyWorkbook = CreateExcelWorkbook() Set oMySheet = oMyWorkbook.Worksheets(1) Call MsgBox(oMySheet.Name)
The following example creates an Excel workbook, fills the first worksheet with random values, and saves this Excel workbook in a new XLSX file. If the value is 47, the example highlights this cell with a red background.
| VBScript | Python |
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")