Custom Toolbar Menu

J

jtanaka

For Word, 2003, I want to be able to create a custom toolbar menu that will
run Insert -> File. I want to build a list of files to insert on the fly by
listing folder/sub-folder contents. The Toolbar action should run Insert->
File on the file selected from this custom dropdown menu.

I'm new to VBA and am looking for suggestions or examples if someone has
done something similar. Or if anyone can suggest a better way to get this
functionality with Word 2003, I'm open to other options.

Thanks!
 
C

Cindy M.

Hi =?Utf-8?B?anRhbmFrYQ==?=,
For Word, 2003, I want to be able to create a custom toolbar menu that will
run Insert -> File. I want to build a list of files to insert on the fly by
listing folder/sub-folder contents. The Toolbar action should run Insert->
File on the file selected from this custom dropdown menu.

I'm new to VBA and am looking for suggestions or examples if someone has
done something similar. Or if anyone can suggest a better way to get this
functionality with Word 2003, I'm open to other options.
I included exactly this in the "Office VBA Macros you can use Today" book from
Holy Macro! publishing. That would certainly be the simplest way to get where
you want to go :)

You say you're "new to VBA": what kind of programming background do you have
(so we know where/how to start)?

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 :)
 
J

jtanaka

Thank you for the book recommendation. My background is in Java, C/C++, but
for this app my wish is to implement some quick and easy to maintain code
since I will not likely be the long term developer on this project.

If you have any other recommendations, please let me know.

Thank you,
Julie
 
C

Cindy M.

Hi Julie,
Thank you for the book recommendation. My background is in Java, C/C++, but
for this app my wish is to implement some quick and easy to maintain code
since I will not likely be the long term developer on this project.
OK... You first need to decide on what method you want to use to transverse the
folder structure and pick up the files. Office can work with Dir,
FileSystemObject (which requires making sure the Scripting Runtime library is
installed and activating a reference to it) or the Office FileSearch
capability. Most people I know work with Dir since it's reliable and doesn't
require any outside DLLs. To get information on how Dir works, type this into
the VBA Editor then press F1 to get to the Help. I think you'll find the
concepts familiar enough that you'll get on with no great problems. Try a
couple of examples until you're getting the list of files you expect.

In order to create the menu you need to work with CommandBars, which are part
of the Office object model (shared by most Office apps). I think you'll find
some basic information at word.mvps.org and other places on the web (do a
Google search, for instance). To create your own menu on the menu bar:
Dim menu as CommandBarPopup
Set menu = Application.CommandBars("Menu bar").Controls.Add('params here)
menu.Caption ="Caption"

Now you'll probably want to loop through the folders and files, creating
buttons as you go. To add a button that opens a file to the dropdown
Dim fileButton as CommandBarButton
Set fileButton = menu.CommandBar.Controls.Add('params)
fileButton.OnAction = "NameOfMacroToRunWhenClicked"
To add another "dropdown level", use a new control of the type CommandBarPopup

Note how a CommandBarPopup has a CommandBar property - this will NOT show up in
the Intellisense, but it's key to building the menu.

Since all the controls will basically run the same macro to insert a file, you
can store the full file path in the controls' Tag or Parameter property. In the
common macro:
rng.InsertFile FileName:=CommandBars.ActionControl.Parameter

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 :)
 
J

jtanaka

Thank you Cindy.

I did pick up a copy of your book and found the examples very helpful! I
just needed to make a few customizations to allow the tree to traverse more
than 3 levels of folders.

Thank you for your help!
Julie
 
C

Cindy M.

Hi Julie,
I did pick up a copy of your book and found the examples very helpful! I
just needed to make a few customizations to allow the tree to traverse more
than 3 levels of folders.
Glad you're up-and running :)

Cindy Meister
 

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