Call Statement

  • Thread starter Thread starter caldog
  • Start date Start date
C

caldog

I know that there is something that is call a 'call statement', but I do not
know how its work. In my code I duplicate about 10 lines in five different
sections of code. What I was wanting to do, was locate the code that I use
quite a bit in one section and then just ask for when I need it.

Thanks
 
Small example with the two Subs in a module to set application properties
when running macros.

Sub set_app()
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayAlerts = False
End With
End Sub

Sub reset_app()
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub

You don't really need the Call statement to add those to your macros.

Sub do_stuff()
set_app

your code to do stuff

reset_app
End Sub

If you wanted to post an example of what 10 lines you duplicate in 5
different routines perhaps you could get more specifics.


Gord Dibben MS Excel MVP
 
I always figured that "Call" was best used in a button.

Private Sub CommandButton1_Click()
Call set_app
End Sub

this way you can code and click a button for the macro to be active...
 
I always assumed that the "call" statement was used for setting a macro to a
button/checkbox...etc

Private Sub CommandButton1_Click()
Call #Name
End Sub
 
Back
Top