What is the syntax to call procedures from another module?

Call <module name>.<sub procedure's name>
#example - project has a userform, and a module called Commands
Private Sub btnRefresh_Click() 'located in a userform
 Call Commands.output
End Sub


Sub output() 'located in Commands module
     MsgBox "This code is in a separate module"
End Sub

 

Advertisements

What is the syntax to declare procedures?

Private Function <your name> ()
   ‘your code here
   ‘callable only by procedures in the same module
End Function


Public Function <your name> ()
   ‘callable from any procedure
End Function

 
Private Sub <your name> ()
   ‘callable only by procedures in the same module
   ‘cannot be called from Macros dialog box
End Sub

 
Public Sub <your name> ()
   ‘callable from any procedure of any module
   ‘can run procedure from Macros dialog box
End Sub

What is a procedure?

  • Grouped statements that relate to a specific task
  • Used for complex tasks that can be further broken down into smaller tasks
  • Two types of procedures: sub and function
Function <name>(<parameters>)
‘callable from anywhere in program
‘can return values
‘put function declarations in a module sheet
End Function
Sub <name>(<parameters>)
‘do not return values
End Sub