Programming Command Bars in Word

A

Alan Lambert

The context of this is a system that will allow standard
pieces of text (e.g. marketing blurb, resumes, case
studies etc.) to be inserted easily into a Word XP
document. These pieces of text will be stored in separate
files within a (flexible) folder structure.

Users will select the text files from a dropdown menu
(CommandBarPopup) on a Command Bar in Word. This menu will
be populated from the physical folder structure on a disc.
This menu may be several layers deep. The piece of text
(from within the selected file) should then be inserted.

Creating the menu is no problem.

I would want to have one procedure that takes as a
parameter the file's path and then inserts the text from
that file into the current document. Creating this
procedure is, again, no problem.

However, the OnAction property for Command Bar Buttons in
Word does not seem to allow parameters to be passed to the
procedure.

If I could reference the button pressed from my procedure
I could use its parameter property to pass the information
but I can't reference the button without passing a
parameter!

I can't create a separate procedure for each file as the
number and names of the files will change and there will,
at a minimum, be 100 different files.

I can't create class modules and declare variables
withevents for the same reason.

I have considered using a database to store the text but,
currently, this is not an acceptable solution. Even so, I
would still need to pass something to the procedure to say
which item from the database should be inserted.

Have I missed something and is there a way round this?
 
J

Jonathan West

Hi Alan

The way to do this is to load the value of the Tag or the Caption property
of the CommandBars.ActionControl object into a string, and use that. So if
for instance, your text file had the same name as the caption of the
control, uou would use a line of code something like this

strTextFile = CommandBars.ActionControl.Caption & ".txt"
 

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