Is there a way to autofit all the columns in the opening sheet which contain data? I'm looking for a solution that is not depended on modifications on a certain excel file but which works on every excel file and runs on excel startup.
You can use an object module that will receive an Application Event (see more info on Chip Pearson's website).
This is the code you have to copy-paste to the module ThisWorkbook
of the file PERSONAL.XLSB
:
Option Explicit
Private WithEvents App As Application
Private Sub Workbook_Open()
Set App = Application
End Sub
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
'Statement to show that it works
MsgBox "Opened Workbook: " & Wb.Name
'Statement to autofit columns
ActiveSheet.UsedRange.Columns.AutoFit
End Sub
You could also add a loop over the workbook sheets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With