Reputation: 13
I am trying to automate a process that will auto adjust the column width of an Excel report. This Excel report is being generated by a query in Access. So, I can't put VBA code in Excel file itself. I need to put VBA code or something else in Access so that whenever I run the query I get auto adjusted column width in output Excel report. I have tried few things but none are working.
'ThisWorkbook.Worksheets("qryFT").Columns.Autofit
'acOutpotquery.Select
'Column("A:A").Select
'Selection.EntireColumn.Autofit
Upvotes: 0
Views: 511
Reputation: 375
Assuming that you've already created the Excel object? Let's call it MyXL
myxl.workbooks.open filename:={path to your Excel sheet}
myxl.activeworkbook.sheets(1).columns(x).autofit
where x = column number
Upvotes: 1