Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
David,
A function declared as Public means that it is Public to the project, as opposed to Private to the code module. A Public function can be called from any module within the same project (workbook). A Private function can be called only from within the module in which it resides. If you want to call the Public function from another project, you must set a reference in the CALLING project to the project with contains the Public function. First, in VBA with the project containing the function active, go to the Tools menu and choose "VBA Project Properties". In that dialog, change the project name from "VBAProject" to something unique and meaningful, like "MyGoodProject" and save the file. Then, in the project that will be calling that function, go to the Tools menu, choose References, and select and check "MyGoodProject" from the list. Once you've established the reference, you can call the Public function simply by name, e.g., Result = MyFunction(1234) If there is a possibility of an ambiguous name (e.g., both projects have a function named MyFunction), you can prefix the function name with the project name. For example: Result = MyGoodProject.MyFunction(1234) This all assumes that you have put your Public Function in a standard code module, NOT the ThisWorkbook module or one of the SheetN modules or a Class module. If you want to go down the References path, you'll have to use Application.Run. E.g., Result = Application.Run ("Book1.xls!MyFunction", 1234) where Book1.xls is the name of the workbook that contains the function. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "David" wrote in message ... Hi Group, I have created a file with a Public function, but the function does not find it. It must be saved where to be truely public? Thanks, -- David |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
protect public sub | Excel Discussion (Misc queries) | |||
Use of PUBLIC | Excel Programming | |||
Dim vs. Public | Excel Programming | |||
public sub | Excel Programming | |||
Public Sub Help | Excel Programming |