Add in template - toolbar shows up multiple times

D

Dorthe

Hi everyone
I have about 10 templates that use the same toolbar, autotexts, styles and
VBA code. Until now I have stored the toolbar, autotexts etc. In each
template.
It wasn't very interesting, when an autotext had to be modified. Then it had
to be modified in each template. This due to the fact that the company I work
for doesn't want a global template for us all.
Now however, I came of the thought that I could just load a template via an
auto new and auto open macro.
Here is my code that I have placed in each of my templates:

Private Sub Document_New()
With ActiveDocument
.UpdateStylesOnOpen = True
End With

AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True

With ActiveDocument
.UpdateStylesOnOpen = True
End With

End Sub

Private Sub Document_Open()
With ActiveDocument
.UpdateStylesOnOpen = True
End With

AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True

With ActiveDocument
.UpdateStylesOnOpen = True
End With

End Sub

It all works fine, but e.g. my toolbar shows up twice each time I start a
new document based on one of my templates. When I close the document, one
toolbar stays on. The functions just doesn't work of course.
I can see that the "Key Template.dot" that now holds all of my autotexts,
the one toolbar and my macros is still loaded, also when no documents are
open anymore.
Can anyone help with this - is it a simple line that needs to be added the
code?
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RG9ydGhl?=,
I have about 10 templates that use the same toolbar, autotexts, styles and
VBA code. Until now I have stored the toolbar, autotexts etc. In each
template.
It wasn't very interesting, when an autotext had to be modified. Then it had
to be modified in each template. This due to the fact that the company I work
for doesn't want a global template for us all.
Now however, I came of the thought that I could just load a template via an
auto new and auto open macro.
Here is my code that I have placed in each of my templates:
Addins is a collection. I'd first check whether the Addin in question is loaded,
and if it's not, load it:

Dim adin as Word.Addin
Dim bAddinLoaded as Boolean

For Each adin in Application.Addins
If adin.Name = "Key template.dot" Then
bAddinLoaded = true
Exit For
End If
If Not bAddinLoaded Then
AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True
End If
Next

Also, make sure that the toolbars are no longer in each individual template
(that's probably why you're seeing them twice).

In order to remove the toolbars, etc. you need to remove (unload) the Addin. You
should be able to do this using a Document_Close procedure, analogous to
Document_Open and Document_New. this should unload the Addin:

Application.Addins("C:\Documents and Settings\DB\Skrivebord\Key
template.dot").Installed = false
Private Sub Document_New()
With ActiveDocument
.UpdateStylesOnOpen = True
End With

AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True

With ActiveDocument
.UpdateStylesOnOpen = True
End With

End Sub

Private Sub Document_Open()
With ActiveDocument
.UpdateStylesOnOpen = True
End With

AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True

With ActiveDocument
.UpdateStylesOnOpen = True
End With

End Sub

It all works fine, but e.g. my toolbar shows up twice each time I start a
new document based on one of my templates. When I close the document, one
toolbar stays on. The functions just doesn't work of course.
I can see that the "Key Template.dot" that now holds all of my autotexts,
the one toolbar and my macros is still loaded, also when no documents are
open anymore.
Can anyone help with this - is it a simple line that needs to be added the
code?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
D

Dorthe

Hi Cindy
Thanks a lot for your answer. The code looks fine, and I was also sure that
it was the needed code. However, I get an error when copying the code into my
Document_open/new instead of my old code.
This comes out red...
AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True

I did remove all the autotexts and toolbar from the 10 single templates. So
that is not the reason why it shows up twice or more times. But let us see,
if we can't get your code to work and I think that solves the problem with
the toolbars.
Can you please advice what might be wrong. The template is locatet at my
desk (skrivebord in Danish) and the name is correct too.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RG9ydGhl?=,
Thanks a lot for your answer. The code looks fine, and I was also sure that
it was the needed code. However, I get an error when copying the code into my
Document_open/new instead of my old code.
This comes out red...
AddIns.Add FileName:= _
"C:\Documents and Settings\DB\Skrivebord\Key template.dot",
Install:=True
Ah, it broke over to an additional line. "Install" should come up to the same
line as the comma. Or you need a space-underline ( _) after the comma.
I did remove all the autotexts and toolbar from the 10 single templates. So
that is not the reason why it shows up twice or more times. But let us see,
if we can't get your code to work and I think that solves the problem with
the toolbars.
Can you please advice what might be wrong. The template is locatet at my
desk (skrivebord in Danish) and the name is correct too.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 

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