Group:  Microsoft Word ยป microsoft.public.word.vba.addins
Thread: HOWTO create macro programmatically for command bar buttons.

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

HOWTO create macro programmatically for command bar buttons.
ATS 28.07.2006 18:33:02
HOWTO create macro programmatically for command bar buttons.

I want to programmatically create a macro that I then programmatically make
a command bar button for to call via its OnAction. I know how to add the
command bar button dynamically and sets its OnAction, but I can not figure
out how to create a macro (or AddIn) programmatically such that the button
could then call it.

What can one do?
Re: HOWTO create macro programmatically for command bar buttons.
"Jezebel" <warcrimes[ at ]whitehouse.gov> 28.07.2006 22:20:08
In principle you can create a macro at runtime through the properties and
methods of the application's VBE object. In practice it's damned
difficult --

1. Most security set-ups completely block any programmatic modification of
the code environment (this is a major virus vulnerability).

2. Making changes to the VBA project resets the project -- that is, stops
any running code and clears all variables.


If you already have an add-in, why can't you set up the macro and the
toolbar in advance?




"ATS" <ATS[ at ]discussions.microsoft.com> wrote in message
news:903DA605-FDB4-4A47-BE8A-0CF57863D7EE[ at ]microsoft.com...
[Quoted Text]
> HOWTO create macro programmatically for command bar buttons.
>
> I want to programmatically create a macro that I then programmatically
> make
> a command bar button for to call via its OnAction. I know how to add the
> command bar button dynamically and sets its OnAction, but I can not figure
> out how to create a macro (or AddIn) programmatically such that the button
> could then call it.
>
> What can one do?


Re: HOWTO create macro programmatically for command bar buttons.
"Jean-Guy Marcil" <NoSpam[ at ]LeaveMeAlone> 29.07.2006 02:52:54
ATS was telling us:
ATS nous racontait que :

[Quoted Text]
> HOWTO create macro programmatically for command bar buttons.
>
> I want to programmatically create a macro that I then
> programmatically make a command bar button for to call via its
> OnAction. I know how to add the command bar button dynamically and
> sets its OnAction, but I can not figure out how to create a macro (or
> AddIn) programmatically such that the button could then call it.
>
> What can one do?

I am curious here..

Why have a macro that creates a macro?

The first macro has to be stored somewhere, no?


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Re: HOWTO create macro programmatically for command bar buttons.
ATS 31.07.2006 13:44:02
Thanks for the reply,

I have seen the VBE object, but I'm not sure how I can use it. As for the
question, "Why have a macro that creates a macro?", I do not have a macro,
nor do I have an AddIn, there are more ways to get to the Application and
Document objects than just macro's and AddIns. It appears that I am going to
have to dynamically create an AddIn just to make this work, and that would be
way too much work, but I do not see a way around it, unless the VBE can help.

At any rate, any sample of a VBE usage that shows how to create a macro that
in turn a button's OnAction can then call?


Re: HOWTO create macro programmatically for command bar buttons.
"Jonathan West" <jwest[ at ]mvps.org> 31.07.2006 14:15:08

"ATS" <ATS[ at ]discussions.microsoft.com> wrote in message
news:903DA605-FDB4-4A47-BE8A-0CF57863D7EE[ at ]microsoft.com...
[Quoted Text]
> HOWTO create macro programmatically for command bar buttons.
>
> I want to programmatically create a macro that I then programmatically
> make
> a command bar button for to call via its OnAction. I know how to add the
> command bar button dynamically and sets its OnAction, but I can not figure
> out how to create a macro (or AddIn) programmatically such that the button
> could then call it.
>
> What can one do?

The macro you create would have to be stored somewhere - probably either in
normal.dot or in an add-in.

There are very good reasons why you should not attempt to touch normal.dot -
no least because you have no means of knowing what somebody else has already
done to it. That means you are best using an add-in.

If you have a single macro you want to use (or a limited set of macros) then
you are best creating the macros in the add-in, creating the matching
toolbar buttons, and then loading or unloading the add-in as required. If
necessary, you can refine things further by changing the Visible property of
individual buttons to show or hide them.

Using the VBE object hierarchy is an iffy prospect - it requires that the
user's PC is set up to trust access to the VB project object, and that is
not the default setting in the latest version of Word.

Take a step back from the immediate question, and describe your overall
project a bit. If we understand what you are trying to achieve, we may be
able to suggest an entirely different approach that will meet your
requirements much better.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net