View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff[_5_] Harald Staff[_5_] is offline
external usenet poster
 
Posts: 47
Default How does "Private" work

Hi Otto

Lots of good explanations are provided.
Great thing with macros on standard module are that they can be called from
everywhere. But they can also be started from the Tools Macro menu, which
sometimes is a very bad idea. A typical set of macros in my apps are "unlock
everything" and "re-lock everything", used by lots of procedures. I don't
want any of my users to ever access those.

So put Private in the name and they disappear from the menu. But then they
can't be called from other modules either. Which is a huge problem. My
solution to this -I never use Private: Put an optional parameter to it
that's not used for anything:

Sub RunStuff(Optional RightNow As Boolean)
MsgBox "Hello world"
End Sub

-and it disappears completely from the user, but still it can be called from
all modules:

Sub SomewhereElse()
Call RunStuff
End Sub

--
HTH. Best wishes Harald
Excel MVP
Followup to newsgroup only please

"Otto Moehrbach" skrev i melding
...
Excel 2002, Win XP
I have a sheet macro:
Private Sub Worksheet_Activate()
Call UpdateSummary
End Sub

The UpdateSummary macro looks like this:
Private Sub UpdateSummary()
'Stuff
End Sub

Upon activation of the sheet, I get an error message on the "Call
UpdateSummary" line that it is not defined. If I remove the word

"Private"
before the Sub UpdateSummary() all works fine. I wanted to ensure that

the
UpdateSummary macro was not displayed in the Tools - Macro - Macros list,

so
I put the "Private".
Obviously there is something here that I don't know. What is it?
Thanks for your help. Otto