Post by ATSHOWTO 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