How to run VBA function from custom toolbar?

K

kiln

I'm used to programming in MS Access. With it, it's simple to run a user
defined function from a custom toolbar. While in the "Customize" mode
for toolbars, the first command item in the File list is "Custom", and
dragging it onto a toolbar creates a toolbar button that has a
Properties page, where a function can be called. I can't find anything
like this in Word 2000. It must be possible to call user defined
functions from a Word toobar, so how it is done?

Thanks
 
C

Chad DeMeyer

kiln,

In Access a macro is something different than in all the other MS Office
apps. In Word etc. macro is just another word for a VBA procedure. So to
add a toolbar button that calls a Word "macro", go to Tools>Customize,
Commands tab. Select the category "Macros" on the left, then find the macro
you want in the list on the right. Make sure you have "Save in" dropdown
set to the document or template where you want this customization to be
saved, then click and drag the macro name to the toolbar where you want its
button. Then if you right-click the new button on the toolbar, you can
change its style between icon/text, assign an icon and/or text, even edit
the icon. This can all be done programmatically as well in VBA.

Regards,
Chad
 
K

kiln

Hi Chad

I tried recording a macro, your steps are a good outline, and basically
the macro didn't record anything. All I did after creating the macro was
to set the Keyword property of the word doc to "transcribed". However
the VBA sub that resulted has nothing in it but a author note and a date
time stamp.

So that macro recorder gets a fail, but I can code the property change
by hand I think. Thanks for your help!
 
J

Jezebel

Right-click any toolbar. Select customise. Select the Commands tab. Select
Macros from the Categories list. Select the macro you want from the Commands
list: click and drag to the toolbar or menu. Initially it will appear on the
toolbar or menu as a fully qualified name. Right click to change this to a
caption or use an icon.

You need to do extra work through VBA if you need to set the command's
Parameter or Tag properties.

For a macro to appear in the commands list it must be public and must not
take arguments.
 
K

kiln

thanks those are some great tips. Strange that the commands can't take
args, but I can work around that.
 
J

Jezebel

You can put the args into the Control's Parameter and Tag properties,
amongst other methods.
 

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