How to hide the Auto* for user use ?

N

natric

[Posted to microsoft.public.word.vba.general and copy sent to the cited author]

Hi,

How to hide the AutoOpen, AutoNew and AutoClose macros from the list
which appears when uqser go to Tools/Macro/Macros.

Knowing, I don't wish to lock access to this list (ie. remove the Macro
command in menu) nor erase these subs in the code by itself (since I
just want to stop the user calls but not the internal ones).

Any idea ?
 
J

Jean-Guy Marcil

natric was telling us:
natric nous racontait que :
[Posted to microsoft.public.word.vba.general and copy sent to the
cited author]

Hi,

How to hide the AutoOpen, AutoNew and AutoClose macros from the list
which appears when uqser go to Tools/Macro/Macros.

Knowing, I don't wish to lock access to this list (ie. remove the
Macro command in menu) nor erase these subs in the code by itself
(since I
just want to stop the user calls but not the internal ones).

Any idea ?

Normally we put the "Private" keyword before Sub on the Sub declaration
line.
But I believe that this will prevent Auto macros from running.

Auto macros are deprecated.

Better use the ThisDocument class module:
Double click on it in the Project browser pane to access its code pane.
In the dropdown list on the left at the top of the code pane, select
"Document".
The following sub will be added to the code pane:

Private Sub Document_New()

End Sub

Now, drop the list on the right to access the other events (Document_Open,
Document_Close up to Word XP, and Document_Sync and 2 types of Document_XML
events for Word 2003)

These will not be listed in the macro list you get when doing ALT-F8.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
N

natric

[Posted to microsoft.public.word.vba.general and copy sent to the cited
author]

no- said:
Normally we put the "Private" keyword before Sub on the Sub declaration
line.
But I believe that this will prevent Auto macros from running.

Yes, effectively, I confirm this behavior. The Auto code has to be a
public sub ; neither private nor function.
Better use the ThisDocument class module:
Double click on it in the Project browser pane to access its code pane.
In the dropdown list on the left at the top of the code pane, select
"Document".
The following sub will be added to the code pane:

Private Sub Document_New()

End Sub

Now, drop the list on the right to access the other events (Document_Open,
Document_Close up to Word XP, and Document_Sync and 2 types of Document_XML
events for Word 2003)

These will not be listed in the macro list you get when doing ALT-F8.

OK, even if I have to manage some stuff in my code (since in my old
AutoNew I did close the doc, then relaying toward a dot opening ; and
this doesn't work if I go through Document_New since its, in this case,
code is embedded in the document itself and by design cannot continue
after a doc.close while it can when we go through AutoNew), it's the
right way. However, since I want to keep code in a module, I've just
renamed the old "Sub AutoNew()" (and same for AutoOpen and AutoClose) as
"Function DocNewHelper()" and call this fct from the "Private Sub
Document_New()" event handler.

Thanks to drive me to the right way, Jean-Guy
 
Top