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!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,311
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
 

Forum statistics

Threads
1,141,740
Messages
5,708,237
Members
421,553
Latest member
Geeyj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top