View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Why doesn't "private" work?

Oooh good idea. In fact you could create a new worksheet, that will house
all of your hiden functions, then in excel, if you look at the worksheet
properties, you can make it Very Hidden. Thus the user would not really know
that the worksheet was present unless they got into the VBA code and looked
at the list of sheets, did a comparison of what they could see and what they
couldn't and found a way then to implement the functions you have but through
alternate means. Let's not forget, if a user really wants something to
happen, they are likely to find a way to make it so...



"Chip Pearson" wrote:

You can put those functions that you don't want to be callable
from a worksheet in a worksheet module (make them public), and
call them with the worksheet codename qualifier. E.g.,

' in Sheet3
Public Function Foo(X)
Foo = X
End Function

' in Module1
Sub AAA()
Dim Res
Res = Sheet3.Foo(123)
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"
wrote in message
...
According to Walkenbach, Private "indicates that the
Function procedure is accessible only to other procedures
in the same module", and "when you create a function that
should be used only in a VBA procedure, you should declare
it Private so that users don't try to use it in a formula".

That is exactly the behavior that I want. But when I create
the following functions, both are callable from formulas in
the spreadsheet:

function foo1(x)
foo1 = foo2(x)
end function

private function foo2(x)
foo2 = x
end function

My intent is that the spreadsheet can have =foo1(1), but
not =foo2(2). However, the latter works :-(.

Bottom line: How can I declare function foo2 so that it is
callable only from the procedures in the same module and
specifically not callable from formulas in spreadsheets?