Word 9.0 Restore default toolbars in cusom template file

N

Nathan

Hi All,

I'm looking all over the place to find reference for this. I need to open a
Word template (.dot) and display it in a viewer, but I've noticed some of
our thousands of templates have custom toolbars saved with them. Is there a
way I can automate removal of all non-standard toolbars or maybe a function
I can invoke that restores it to default or even ignores custom toolbars all
together?

I'm using automation inside C# with the Word 9.0 library on a server side
background process. It basically picks up Word dots, modifies and saves
them.

Any suggestions will be appreciated!

Thanks,
Nathan Bridgewater
 
C

Cindy M.

Hi Nathan,
I'm looking all over the place to find reference for this. I need to open a
Word template (.dot) and display it in a viewer, but I've noticed some of
our thousands of templates have custom toolbars saved with them. Is there a
way I can automate removal of all non-standard toolbars or maybe a function
I can invoke that restores it to default or even ignores custom toolbars all
together?

I'm using automation inside C# with the Word 9.0 library on a server side
background process. It basically picks up Word dots, modifies and saves
them.
Well, server-side is a bad idea, in any case, when it comes to automating
office applications... You may want to re-consider this aspect and run it on a
machine where you can dismiss any dialog boxes that pop up.

You could, conceivably, open the templates, set CustomizationContext to the
file you just opened, then do a foreach on the CommandBars collection, checking
the BuiltIn and/or Name property. If it's something you don't want to display,
set the Visible property to false (or delete if it's custom - if you're certain
you want to do this).

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

Nathan

Thanks Cindy!

I looked into this a bit further and found some very strange results. I
wrote a basic app that loops through the CommandBars collection and sets all
menus' Visible to false (with exception ot Menu Bar).

//oDoc is the loaded template file.

this.m_WordApp.CustomizationContext =
(object)this.m_WordApp.ActiveDocument.get_AttachedTemplate();
foreach(Office.CommandBar bar in oDoc.CommandBars)
{
if (bar.Enabled && bar.Visible && !bar.Name.ToUpper().Trim().Equals("MENU
BAR"))
{
bar.Visible = false;
}
}

While I was testing this, I would frequently test my normal Word behavior to
see what menus globally are affected before and after running this script.
My end goal is to remove a Reviewing menu bar that only appears when you
open this one template file. What I'm getting when I run this script is
removal of all toolbars (naturally), but from the global whatever that
they're stored in and not just the template itself, so when I open normal
Word up, the toolbars are also missing.

Afterwards, when I re-add the standard and formatting bars to normal Word
and then re-open the modified template file (with a new instance of Word),
they show up in the template like they should without the Reviewing bar. I
then open up the original template file and the Reviewing bar is there like
you would expect. Then immediately after, if I open up the modified template
file, the Reviewing bar is back. This is the quirky thing I can't seem to
get a grasp on.

I also ran this script without the context change which produced the same
results.

Any ideas? Like I said, my main goal is to remove the Reviewing bar from
appearing when you open this specific template file.

Thanks for your help!
Nathan
 
C

Cindy M.

Hi Nathan,

The Reviewing "toolbar" is special. Although I can no longer remember the
details of how it worked in Word 2000, its appearance is usually linked to
something in the document/template. Does this template contain tracked changes?
Or is that functionality active in the template?

Please note, also, that using ActiveDocument can be tricky. Are you sure you're
executing this when a document attached to this template is active, and not
another one? I also note that you can't actually automate the Word Viewer. I
answered your first question literally, without going into any of the
background...
I looked into this a bit further and found some very strange results. I
wrote a basic app that loops through the CommandBars collection and sets all
menus' Visible to false (with exception ot Menu Bar).

//oDoc is the loaded template file.

this.m_WordApp.CustomizationContext =
(object)this.m_WordApp.ActiveDocument.get_AttachedTemplate();
foreach(Office.CommandBar bar in oDoc.CommandBars)
{
if (bar.Enabled && bar.Visible && !bar.Name.ToUpper().Trim().Equals("MENU
BAR"))
{
bar.Visible = false;
}
}

While I was testing this, I would frequently test my normal Word behavior to
see what menus globally are affected before and after running this script.
My end goal is to remove a Reviewing menu bar that only appears when you
open this one template file. What I'm getting when I run this script is
removal of all toolbars (naturally), but from the global whatever that
they're stored in and not just the template itself, so when I open normal
Word up, the toolbars are also missing.

Afterwards, when I re-add the standard and formatting bars to normal Word
and then re-open the modified template file (with a new instance of Word),
they show up in the template like they should without the Reviewing bar. I
then open up the original template file and the Reviewing bar is there like
you would expect. Then immediately after, if I open up the modified template
file, the Reviewing bar is back. This is the quirky thing I can't seem to
get a grasp on.

I also ran this script without the context change which produced the same
results.

Any ideas? Like I said, my main goal is to remove the Reviewing bar from
appearing when you open this specific template file.

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

Nathan

Thanks Cindy! I think that's exactly what it was. Wow I think I overkilled
that one. I'm an Office noob! :)

I ended up turning on and off "Track Changes", then removed the Reviewing
command bar, and saved the template file. The bar doesn't show when I open
that template. Even if I open the original one first.

Thanks so much!
Nathan
 

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