main() Function
Accessing the active workbook
All your office scripts must have the following function declaration
function main(workbook: ExcelScript.Workbook) {
}
Getting the user to input a message
Add a variable to the main function and then use this variable in your script.
This allows you to display a userform asking the user for some input.
function main(workbook: ExcelScript.Workbook, message: string) {
let selectedSheet = workbook.getActiveWorksheet();
selectedSheet.getRange("A1").setValue(message);
}
When this scripts runs it will prompt the user asking for a message.
![]() |
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext
