How to call function from another specific workbook in VBA?

In the workbook you want to call from (I’ll call this A), you could add a reference to the workbook that you want to call to (I’ll call this B) as follows:

  1. In workbook A, open the Microsoft Visual Basic for Applications window (for example, by pressing Alt+F11).
  2. Select Tools, References.
  3. In the References dialog that appears, choose Browse.
  4. In the Add Reference dialog that appears, choose Microsoft Excel Files from the Files of type box, select the file that you want to call (B), and choose Open.
  5. Choose OK to close the References dialog.

In file A, you should then be able to call public module-level functions in file B as if they were in file A. To resolve any naming conflicts, you can prefix calls by the “Project Name” for file B as specified in the General tab of the Project Properties dialog (accessible via the Properties command in the Microsoft Visual Basic for Applications Tools menu). For example, if the “Project Name” for file B was “VBAProjectB”, you could call function F from file A using the syntax VBAProjectB.F.

Leave a Comment