Calling methods from another Excel file

sbendbuckeye

Active Member
Joined
Nov 26, 2003
Messages
440
Hello all,

We have several different files which share a common path up to a point. I would like to create a code only file and load it into the AltStartUp folder so that it is automatically loaded each time. I would like this file to expose methods for returning the various pieces of path information so that everything is in one place and the other files can read it from there.

If PathInfo.xls is loaded hidden, how do I reference its code methods from other workbook files? Thanks in advance for any ideas and/or suggestions!
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,977
Office Version
  1. 2016
Platform
  1. Windows
Look up the Run Method in the Help files.

Regards.
 

sbendbuckeye

Active Member
Joined
Nov 26, 2003
Messages
440
Thanks, that is helpful. Can you pass arguments ByRef using Application.Run? It doesn't appear that you can based on current testing.
 

sbendbuckeye

Active Member
Joined
Nov 26, 2003
Messages
440
For the benefit of others, you can put standard methods in any of the Excel class code (eg ThisWorkBook, Sheet1, Sheet2, etc) and then call them as normal. They even shows up in intellisense and can accept ByRef parameters. The following code assumes that you have defined MySub and MyFunction within ThisWorkBook for a file with named "YourFileSpec".
Code:
Dim wkb As Workbook
Set wkb = WorkBooks.Open(FileName:="YourFileSpec", UpdateLinks:=False, ReadOnly:=True, AddToMru:=False)
Call wkb.MySub()
MsgBox Wkb.MyFunction
wkb.Close SaveChanges:=False
Set wkb = Nothing
 

Watch MrExcel Video

Forum statistics

Threads
1,111,598
Messages
5,541,163
Members
410,543
Latest member
ExcelGlenn
Top