Forum Discussion
Patrick_virtualFD
Jan 18, 2023Brass Contributor
Office script version of VBA for column autofit?
hi everyone, Do you know if there's a way to mimic the behaviour of the VBA command cells.entirecolumn.autofit using Office Script? I've managed to get this behaviour on a particular table (a...
- Feb 03, 2023You can use something like:
selectedSheet.getRange("D8:J8").getFormat().autofitColumns();
See:
https://learn.microsoft.com/en-gb/office/dev/scripts/tutorials/excel-read-tutorial
wma1840
Feb 03, 2023Copper Contributor
You can use something like:
selectedSheet.getRange("D8:J8").getFormat().autofitColumns();
See:
https://learn.microsoft.com/en-gb/office/dev/scripts/tutorials/excel-read-tutorial
selectedSheet.getRange("D8:J8").getFormat().autofitColumns();
See:
https://learn.microsoft.com/en-gb/office/dev/scripts/tutorials/excel-read-tutorial
- Patrick_virtualFDFeb 06, 2023Brass ContributorNice. That works as part of:
function main(workbook: ExcelScript.Workbook) {
//define what the selectedSheet means
let selectedSheet = workbook.getActiveWorksheet();
//apply column width auto-format to the selectedSheet object
selectedSheet.getRange("A1:BZ1000").getFormat().autofitColumns();
}
Is there any way to get this to run after each and every data input to the sheet? Or can these scripts only be run via manual trigger?