Copy commandbar from template to normal.dot

B

birger100

Hey,
I want to copy a commandbar from my current template to the normal.dot
template.
This has to happen when the user opens the template, so it has to be
done i VBA code.
It also have to make a check to see if the commandbar is already in
the normal.dot file.

I have seached the internet and haven't really found anything that
could solve me problem... hope that there is someone in here that has
a solution.


Mvh
Birger
 
L

Lene Fredborg

If you insert the code below in an appropriate AutoMacro, the code should do
what you want. However, there are several things to consider:

1. It may not be a good idea to change the users' Normal.dot. Why can't the
toolbar just remain in the original template? If you wish the toolbar to be
available to all documents, you could install the template in the users'
Startup folder.

2. Which commands are in the toolbar? If the commands execute macros, the
macros must also be available in order to work. However, if the toolbar only
contains a collection of built-in commands, it should work.

3. The code below saves Normal.dot in order to keep the toolbar there
permanently. You may not want to do that.

Links to relevant articles:
About AutoMacros:
http://word.mvps.org/faqs/macrosvba/DocumentEvents.htm
About distributing macros to other users:
http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm

The code:

Dim strBarName As String
Dim oBar As CommandBar
Dim bBarFound As Boolean

'Replace the name by the correct commandbar name
strBarName = "MyToolbar"
bBarFound = False
'Check whether commandbar is already found in Normal.dot
For Each oBar In CommandBars
If oBar.Name = strBarName Then
If oBar.Context = NormalTemplate.FullName Then
' the commandbar is in Normal.dot
bBarFound = True
'No need to check more
Exit For
End If
End If
Next oBar

If bBarFound = False Then
CustomizationContext = NormalTemplate
Application.OrganizerCopy _
Source:=ThisDocument.FullName, _
Destination:=NormalTemplate.FullName, Name:=strBarName, _
Object:=wdOrganizerObjectCommandBars
'Save Normal.dot
NormalTemplate.Save
End If

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
B

birger100

Hey,
Thanks for the input.
I need to change the normal.dot because we use a document management
system that uses the normal.dot file to create a new doc with the
contens of the old file and save that to the system. If the normal.dot
is not changed to include my commandbar, the commandbar will not be
saved into the management systemt og therefor we are not able to use
the functionality in the commandbar when we opens the doc from the
management system.

I have consided all the points your making and I know that it is not a
very good idea to change the normal.dot file. But as the situation is
right now we don't really have alot of other options if we want to
avoid making alot of new templates.

Again thanks for the help.
I will try your code sometime today..

Birger
 

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