A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
I understand that you want to change the behaviour of Excel using a VBA code... for whatever reason.
Your question (how to run the code when the file is opened) was really simple and my answer is still pretty basic: Run the same code in Workbook_Open.
This can cause of course issues ... maybe the sheet is already protected... maybe it's not a worksheet... un-/protect sheets automatically using code is from my point of view not a good idea, but it's your file. 😉
Andreas.
Private Sub Workbook_Open()
With ActiveSheet
.EnableOutlining = True
.Protect Password:="Demo", UserInterfaceOnly:=True
End With
End Sub