Edit ONAction of a commandbutton on custom toolbar?

J

JB

Hi Folks,
I've got a custom toolbar that has a macro dropped onto it for a Sub in
an Addin.

Is there any way I can edit the button to point to a private sub in the
addin?

Cheers

J
 
P

Peter Hewett

Hi JB

If you mean a Sub declared with the keyword Private as in:

Private Sub TestMyScope()
End Sub

Then the answers no. For a macro to appear in the list of available macros it must meet
the following constraints:

1. The macro must be in a standard Module, not a Class Module or Form.
2. The Module cannot use the "Option Private Module" statement.
3. The macro must be declared as a Sub and not a Function.
4. The Sub is not allowed any parameters.
5. The sub must be declared Public or no scope keyword used at all in which case Public is
assumed.

HTH + Cheers - Peter
 
J

JB

Peter said:
Hi JB

If you mean a Sub declared with the keyword Private as in:

Private Sub TestMyScope()
End Sub

Then the answers no. For a macro to appear in the list of available macros it must meet
the following constraints:

1. The macro must be in a standard Module, not a Class Module or Form.
2. The Module cannot use the "Option Private Module" statement.
3. The macro must be declared as a Sub and not a Function.
4. The Sub is not allowed any parameters.
5. The sub must be declared Public or no scope keyword used at all in which case Public is
assumed.

HTH + Cheers - Peter
HI Peter,
Where did you find this info? Do you have a link you can send me?
Reason I ask is that I made another copy of the addin, changed the sub
to public, added the macro to the toolbar, deleted the copied addin with
the public version of the sub, then run the macro from the toolbar
sucessfully.

Should it work this way? The one I'm using is definatley a Private Sub.

Cheers

J
 
P

Peter Hewett

Hi JB

Sorry there's no link, just hard won experience! Notice that I qualified my original
response with <For a macro to appear in the list of available macros>. There are numerous
work-arounds for all sorts of things in Word. I don't advocate the method you are using
as you don't know what method Word is using to identify the macro. In the future you
could make some seemingly innocuous change to your code and have it stop working or
upgrade Word and find it doesn't work!

When I need to expose a procedure in this way I normally just bite the bullet and declare
it Public, which is more appropriate as it accurately describes the scope of the
procedure. You could keep it Private but expose a Public stub. But the latter does seem a
tad pointless.

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top