Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2006

Tip: Looking for answers? Try searching our database.

HOWTO create macro programmatically for command bar buttons.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ATS - 28 Jul 2006 19:33 GMT
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?
Jezebel - 28 Jul 2006 23:20 GMT
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?

> HOWTO create macro programmatically for command bar buttons.
>
[quoted text clipped - 6 lines]
>
> What can one do?
Jean-Guy Marcil - 29 Jul 2006 03:52 GMT
ATS was telling us:
ATS nous racontait que :

> HOWTO create macro programmatically for command bar buttons.
>
[quoted text clipped - 5 lines]
>
> 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?

Signature

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

ATS - 31 Jul 2006 14:44 GMT
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?
Jonathan West - 31 Jul 2006 15:15 GMT
> HOWTO create macro programmatically for command bar buttons.
>
[quoted text clipped - 6 lines]
>
> 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.

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.