HOWTO Add script to a Word project for a CommandBarButton to call.

A

ATS

HOWTO Add script to a Word project for a CommandBarButton to call.

Please help,

I'm trying to add a button to the active menu bar to calls my script. I have
found easily how to add the command bar button, and set its OnAction, but I
do not see how I can create script dynamically that in turn the button will
then call. I have tried the Scripts collection to add script, but right off
the bat, I do not see where the script "ends" up, and the OnAction can not
seem to call it.

I have also looked at AddIns, but AddIns wants a file, and I'm trying to add
the script dynamically, so AddIns "Add" method will not work.

What can I do?
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?QVRT?=,
I'm trying to add a button to the active menu bar to calls my script. I have
found easily how to add the command bar button, and set its OnAction, but I
do not see how I can create script dynamically that in turn the button will
then call. I have tried the Scripts collection to add script, but right off
the bat, I do not see where the script "ends" up, and the OnAction can not
seem to call it.

I have also looked at AddIns, but AddIns wants a file, and I'm trying to add
the script dynamically, so AddIns "Add" method will not work.
1. Which programming environment are you working in?

2. Which application are you automating?

General information: The "OnAction" property can only be assigned to VBA code
in an Office project "visible" to the toolbar button. You cannot use this to
link to "script" outside the Office application in which you're creating the
button. If your script is something else, then you have to sink the button's
Click event.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
A

ATS

Thanks for the reply.

Is there a way I can create dynamically a macro with something like
Application."Macros???".Add? And then assign the OnAction to call my macro?
 
A

ATS

I've been researching more, and I think I can explain what I want better.

I want to add a command bar button, whose "OnAction" call script that I
dynamically create. Sadly, the Document.Scripts does not let me do this. And
Application.AddIns wants a file that is either a OLE object (WLL, DLL, etc),
or a template. Either one is a file, and I do not want to use a file. IS
there not a way with Word/Office to be able to create script that command bar
buttons can call?

If not, is there a way to change the current template of the current
document or application to have new macros that in turn the command bar
button can call?
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?QVRT?=,
I've been researching more, and I think I can explain what I want better.

I want to add a command bar button, whose "OnAction" call script that I
dynamically create. Sadly, the Document.Scripts does not let me do this. And
Application.AddIns wants a file that is either a OLE object (WLL, DLL, etc),
or a template. Either one is a file, and I do not want to use a file. IS
there not a way with Word/Office to be able to create script that command bar
buttons can call?

If not, is there a way to change the current template of the current
document or application to have new macros that in turn the command bar
button can call?
As you've posted your question in a Word VBA newsgroup and gotten responses
there, I'm not going to repeat what Jezebel and Jean Guy have already told you.
I agree with the information they've given.

Theoretically, you can change the AttachedTemplate property. Whether it will do
exactly what you have in mind I cannot judge, however. Based on what I gather
from your messages, I think it would be safer to have the additional commandbar
buttons in there own commandbar, saved IN the template you'd be attaching. (But
note that here, again, you'd need a separate file).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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