Home > OS >  How to make Sub AddSum() run automatically when the excel starts
How to make Sub AddSum() run automatically when the excel starts

Time:04-19

I have a code under Addsum(), which needs to be automatically run when the excel starts.

I have tried several ways like

Sub Auto_open
  Sub Addsum()
     ...code
  End Sub
End Sub

another method like calling other subs option,

Sub RunAll()
  Call Auto_Open
  Call AddSum
End Sub

but none seems to satisfy the requirement as running the Addsum() immediately when the workbook opens.

Please guide me!

CodePudding user response:

As @TimWilliams has shown, first place your AddSum procedure in a regular module (Insert >> Module) . . .

Sub AddSum()
   ...code
End Sub

Then call your procedure from your Auto_open event handler in the code module for ThisWorkbook . . .

Sub Auto_open()
  AddSum
End Sub
  • Related