Collapse the table of content
Expand the table of content
Expand Minimize

Calling Procedures with the Same Name


Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

You can call a procedure located in any module in the same project as the active module just as you would call a procedure in the active module. However, if two or more modules contain a procedure with the same name, you must specify a module name in the calling statement, as shown in the following example:

Sub Main() 
End Sub 

If you give the same name to two different procedures in two different projects, you must specify a project name when you call that procedure. For example, the following procedure calls the Main procedure in the MyModule module in the MyProject.vbp project.

Sub Main() 
End Sub 

Note Note

Different applications have different names for a project. For example, in Microsoft Access, a project is called a database (.mdb); in Microsoft Excel, it's called a workbook (.xls)

  • If you rename a module or project, be sure to change the module or project name wherever it appears in calling statements; otherwise, Visual Basic will not be able to find the called procedure. You can use the Replace command on the Edit menu to find and replace text in a module.

  • To avoid naming conflicts among referenced projects, give your procedures unique names so you can call a procedure without specifying a project or module.

© 2015 Microsoft