LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Public?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
protect public sub johnny Excel Discussion (Misc queries) 2 April 23rd 08 07:04 PM
Use of PUBLIC BillCPA Excel Programming 6 June 7th 06 01:41 PM
Dim vs. Public Jason Morin Excel Programming 7 January 27th 05 01:13 PM
public sub Bob Excel Programming 3 December 10th 04 08:49 PM
Public Sub Help No Name Excel Programming 2 May 18th 04 11:09 PM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"