Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How does "Private" work

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default How does "Private" work

Otto,

These two modules are in different code modules, one in a sheet code module,
the other in (I presume) a normal code module. You cannot invoke Private
procedures across different modules.

If you include an 'Option Private Module' in the code module, those
procedures will not show in the macro list, but will still be available to
other modules in that project. The one thing you won't be able to do is to
invoke them from another project (workbook).

--

HTH

Bob Phillips

"Otto Moehrbach" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default How does "Private" work

Put it in the same sheet module and you won't get the message.

"Otto Moehrbach" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How does "Private" work

Bob
Thanks for your help and thanks for taking the time to explain it to me.
Otto
"Bob Phillips" wrote in message
...
Otto,

These two modules are in different code modules, one in a sheet code

module,
the other in (I presume) a normal code module. You cannot invoke Private
procedures across different modules.

If you include an 'Option Private Module' in the code module, those
procedures will not show in the macro list, but will still be available to
other modules in that project. The one thing you won't be able to do is to
invoke them from another project (workbook).

--

HTH

Bob Phillips

"Otto Moehrbach" wrote in message
...
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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How does "Private" work

Don
Thanks for your help but how can I put a sheet macro and a regular macro
in the same module? I can put all the code in the sheet macro and that
would do it. Thanks again. Otto
"Don Guillett" wrote in message
...
Put it in the same sheet module and you won't get the message.

"Otto Moehrbach" wrote in message
...
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








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default How does "Private" work

Otto,

From the VBA help on "Sub Statement"

Private Optional. Indicates that the Sub procedure is accessible only to
other procedures in the module where it is declared.

Put the sub in the sheet module and use

Private Sub Worksheet_Activate()
Macro1
End Sub

Private Sub Macro1()
*code*
End Sub

--
sb
"Otto Moehrbach" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default How does "Private" work

Or another way is to leave it private, but run it using Run, which can call
private procedures and functions:

Application.Run "UpdateSummary" 'The Application part is optional


"Otto Moehrbach" wrote in message
...
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




  #8   Report Post  
Posted to microsoft.public.excel.programming
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




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How does "Private" work

That's a good point to remember. Thanks. Otto
"Tim Zych" wrote in message
...
Just to note, there might be issues if code is moved behind the worksheet.

Unqualified range references in sheet code always reference the sheet that
holds the code, whereas in a module, they reference the active sheet. It
depends on what your code does, to determine if putting it behind a sheet

is
the best choice. As a matter of personal preference, I tend to allow some
sheet level event code behind the sheet, but not much more. Hard to say

how
it would affect your macro because we don't know what it does. Since your
original goal was to simply hide the macro visibility from the Tools menu,
you may be safest simply by adding Option Private Module at the top of the
module and making the sub public, like Bob suggested (although I like Run
for some things too).

Best regards,
Tim Zych


"Otto Moehrbach" wrote in message
...
Steve
You taught me something I didn't know. I didn't know I could put a
regular (non-event) macro in a sheet module. Thanks. Otto
"steve" wrote in message
...
Otto,

From the VBA help on "Sub Statement"

Private Optional. Indicates that the Sub procedure is accessible only

to
other procedures in the module where it is declared.

Put the sub in the sheet module and use

Private Sub Worksheet_Activate()
Macro1
End Sub

Private Sub Macro1()
*code*
End Sub

--
sb
"Otto Moehrbach" wrote in message
...
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












Reply
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
=SUBSTITUTE(C4,"~?#","") will this work to remove multiple string Raja Mahendiran S Excel Worksheet Functions 6 May 12th 10 09:10 PM
how does this formula work: =LOOKUP(2,1/((COUNTIF(D6:D41,""&D6:D41)=0)*(D6:D41<"")),D6:D41) Dave F[_2_] Excel Discussion (Misc queries) 7 February 1st 09 03:42 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
pictures to work with "data" "sort" option arad Excel Discussion (Misc queries) 1 April 18th 06 09:15 PM
Why doesn't "Workbook.Range("myrange").value" work? Brad Patterson Excel Programming 0 July 9th 03 01:24 AM


All times are GMT +1. The time now is 05:56 PM.

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

About Us

"It's about Microsoft Excel"