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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thanks, that is helpful. Can you pass arguments ByRef using Application.Run? It doesn't appear that you can based on current testing.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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
Back
Top