Share Toolbar for multiple templates

M

mamue

Hi,

is it possible to share a toolbar to use it within multiple templates?
I've put the template with the toolbar to be shared in the office
startup folder, but i want the toolbar to appear only in specific
templates, not in everyone.

cheers, matthias
 
G

Graham Mayor

You could remove it to the specific templates?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mamue

You could remove it to the specific templates?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Sorry Graham, i didn't understand what you mean with "removing to
specific templates".

cheers, matthias
 
J

Jean-Guy Marcil

mamue said:
Hi,

is it possible to share a toolbar to use it within multiple templates?
I've put the template with the toolbar to be shared in the office
startup folder, but i want the toolbar to appear only in specific
templates, not in everyone.

For this to truely work, you will need application events.
You need to detect when a document is created/opened, then you need to check
the attached template, if it belongs to your list, display the toolbar,
otherwise hide it. Then, becasue a user may work with many documents at once,
all based, maybe, on different templates, you also need to detect when the
user changes from document to document and display/hide the toolbar as
appropriate. I have done something like this in the past and I can assure you
that it is not trivial. For someone who has experience with VBA and
Application events, it is not difficult, but it does take some time as a fair
amount of code has to be written and checked.

If you are a VBA beginner, this is quite a challenge! In any case, since you
need to go through Application Events, you may want to find out about them,
start here:
http://word.mvps.org/faqs/macrosvba/AppClassEvents.htm
 
G

Graham Mayor

Currently you have the toolbar in a global template, which by implication
will make it available to all documents. if you only want it applicable only
to certain document templates, then copy it to those templates (using the
organizer) and remove it from the global template. If buttons on the toolbar
call macros stored elsewhere, you will probably have to re-add the macro
buttons to the toolbars after you have moved them.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mamue

For this to truely work, you will need application events.
You need to detect when a document is created/opened, then you need to check
the attached template, if it belongs to your list, display the toolbar,
otherwise hide it. Then, becasue a user may work with many documents at once,
all based, maybe, on different templates, you also need to detect when the
user changes from document to document and display/hide the toolbar as
appropriate. I have done something like this in the past and I can assure you
that it is not trivial. For someone who has experience with VBA and
Application events, it is not difficult, but it does take some time as a fair
amount of code has to be written and checked.

If you are a VBA beginner, this is quite a challenge! In any case, since you
need to go through Application Events, you may want to find out about them,
start here:
http://word.mvps.org/faqs/macrosvba/AppClassEvents.htm

Thanks Jean-Guy, i'll check that page, altough i hope for a more
trivial way ;-)
 
J

Jean-Guy Marcil

mamue said:
Thanks Jean-Guy, i'll check that page, altough i hope for a more
trivial way ;-)

If you want an easy/trivial way, I believe that Graham's suggestions fits
the bill.
One minor drawback is that you will have to maintain multiple instances of
the same code.
One major drawback is that if a user works on two documents, each one being
based on two different templates, there will two instances of the toolbar on
the UI. If you have 5 different templates, you could end up with 5 instances
of the toolbar on the UI...
 
J

Jonathan West

mamue said:
Hi,

is it possible to share a toolbar to use it within multiple templates?
I've put the template with the toolbar to be shared in the office
startup folder, but i want the toolbar to appear only in specific
templates, not in everyone.

cheers, matthias

Hi Matthias

Both Graham and Jean-Guy have given you parts of the answer, but they have
complicated things a bit.

Proceed as follows:

For each template whose documents you want to display to the toolbar, copy
the toolbar from your global template to the document template.

When you have done this, delete the toolbar from your global template.

The toolbar will now only be visible when a document based on one of those
individual templates is active. The buttons will work as normal, provided
that the global template is loaded as an add-in. The best way to do that is
for the global template to be put in the startup folder so it is loaded when
Word is started.

That really is all there is to it.

You can then if you wish customise the toolbar for each individual template,
removing buttons that aren't needed for that document type.
 
J

Jean-Guy Marcil

Jonathan West said:
Proceed as follows:

For each template whose documents you want to display to the toolbar, copy
the toolbar from your global template to the document template.

When you have done this, delete the toolbar from your global template.

The toolbar will now only be visible when a document based on one of those
individual templates is active. The buttons will work as normal, provided
that the global template is loaded as an add-in. The best way to do that is
for the global template to be put in the startup folder so it is loaded when
Word is started.

That really is all there is to it.

Hi Jonathan,

I'll be... !!! I have tried something like this in the past and I seem to
remember that I had a problem regarding the multiple appearance of the
toolbar according to the number of active attached templates. I guess I must
have done someting different from what you outlined... Maybe my
overly-cautious nature made me name each toolbar differently... This must be
why your approach does not have this problem... All toolbars have the same
name, right? If not, why is it that even if you have 3 active attached
templates you still get only one instance of the toolbar?

Thanks... again!
 
J

Jean-Guy Marcil

Jean-Guy Marcil said:
overly-cautious nature made me name each toolbar differently... This must be
why your approach does not have this problem... All toolbars have the same
name, right? If not, why is it that even if you have 3 active attached
templates you still get only one instance of the toolbar?

Never mind... I must have gone to bed too late last night!
As long as you do not have three template in the global folder, each
document has only one attached template, so of course, only one toolbar will
be displayed at the time...

I think that I am confusing issues here becasue I had a project where I had
to use a few global templates... Hence the problem I had with the many
toolbars... I can't remember the specifics... It was a few years ago... (Or
it may have been another project where the toolbar had to be diffrent
depending on the type of document, but the client wanted only one template...
So I needed Application events to check the type of document being displayed
and modify the toolbar on the fly...)

That'll teach me to try to help somebody based on a hazy recollection!

Thanks for your input!
 
J

Jonathan West

Jean-Guy Marcil said:
Never mind... I must have gone to bed too late last night!
As long as you do not have three template in the global folder, each
document has only one attached template, so of course, only one toolbar
will
be displayed at the time...

I think that I am confusing issues here becasue I had a project where I
had
to use a few global templates... Hence the problem I had with the many
toolbars... I can't remember the specifics... It was a few years ago...
(Or
it may have been another project where the toolbar had to be diffrent
depending on the type of document, but the client wanted only one
template...
So I needed Application events to check the type of document being
displayed
and modify the toolbar on the fly...)

That'll teach me to try to help somebody based on a hazy recollection!

Thanks for your input!

This is the standard way I proceed these days for my commercial templates. I
have a lot of VBA code for them, and it makes sense to have it included in
the overall project only once, and have the individual templates use the
bits they need from a customized toolbar in the document template which
calls code in the add-in.
 
M

mamue

This is the standard way I proceed these days for my commercial templates. I
have a lot of VBA code for them, and it makes sense to have it included in
the overall project only once, and have the individual templates use the
bits they need from a customized toolbar in the document template which
calls code in the add-in.

Thanks to all of you. The willingness to help in this group is
amazing. I copied the toolbar Jonathan's way. And it works ;-)
 

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