Limit customization to single instance of Word

P

Petr Danes

I use automation to display results of queries from an Access database into
a Word document. The display is fairly heavily customized: I write out a
template, call the template and have it read in an XML file that I generate
in Access. It sets up custom toolbars, task panes and the document map,
displays the XML results, and puts everything back when closing. All this
works fine, but if the user has this open and wants to open another instance
of Word at the same time, all the custom display settings show up in the new
document as well. I thought that



CustomizationContext = ActiveDocument



would limit this to my app, but it doesn't. Am I using it wrong, is there
another way to do it, is it possible at all?



Petr
 
J

Jean-Guy Marcil

Petr Danes was telling us:
Petr Danes nous racontait que :
I use automation to display results of queries from an Access
database into a Word document. The display is fairly heavily
customized: I write out a template, call the template and have it
read in an XML file that I generate in Access. It sets up custom
toolbars, task panes and the document map, displays the XML results,
and puts everything back when closing. All this works fine, but if
the user has this open and wants to open another instance of Word at
the same time, all the custom display settings show up in the new
document as well. I thought that


CustomizationContext = ActiveDocument



would limit this to my app, but it doesn't. Am I using it wrong, is
there another way to do it, is it possible at all?

CustomizationContext is about the container that will store the custom
changes.

In your case, I would use a DocumentChange Event in order to track when user
navigates from one document to another, and then show/hide whatever is need
depending on the document that becomes active.

See here for some pointers:
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm
 
P

Petr Danes

Hello Cindy,

Been a long time :)

Which version of Word is involved?

2003, almost exclusively so far, although I'm going to be running this on
some 2007 machines soon, which will provide me with more material for fits
and tantrums, setting up code for both toolbars and the ribbon.

In 2003 and earlier it should limit the commandbars'
contents. But what other kinds of "display settings"
are you concerned about?

Display of the document map, task pane, and hiding of all command bars
except mine, to give more vertical room on the screen. The command bar
(toolbar) I add does get displayed only in the document generated from
Access, but the ones I hide are hidden in all new instances of Word, and the
document map and task pane are also displayed in all new instances.

Word is capable of keeping toolbar and such displayed or not displayed in
separate instances; when I switch toolbars on and off manually, the effect
is limited to the instance in which I do it, but when I have only the one
instance running, all new instances take their cue from that (customized)
instance.

Word will "copy" the current window settings to a
new document, for example. So Jean-Guy's
recommendation about using an application event is
probably something you'll have to do in any case.

Sounds like that may be my only choice. Seems like a lot of work for very
little return, though. My 'solution' may be to just leave the toolbars on
and tell the user to deal with the task pane and document map, much as I
dislike that sort of resignation. One other thing just occurred to me: Maybe
if I start a hidden instance of Word, then start my own app, the initial one
will hold sway and subsequent instances will mimic it, rather than my
customized copy. Kind of a tacky approach, but maybe worth a try. I'll give
it a shot and let you know.

Petr
 
P

Petr Danes

In your case, I would use a DocumentChange Event in
order to track when user navigates from one document
to another, and then show/hide whatever is need
depending on the document that becomes active.

Okay, thank you, I'll study that web page and try the technique. Seems like
quite a bit of work for something that Word is already capable of
maintaining on its own, and does in fact. When new instances are customized
manually, the changes appear only in that instance, so clearly Word can keep
track of all those setting on a per-instance basis.

All I want is for Word to stop imitating my currently open app and open new
instances in the standard manner, which doesn't seem to me should be all
that difficult - I would have thought that CustomizationContext would
contain ALL my setting changes to the current instance, but apparently it
doesn't work quite that way.

Petr
 
A

Art H

Hi Petr,


Yes, that could work. Especially since, if the user tries to start Word, it
should call that instance to the front. What happens if the user then quits
that instance and later starts a new one is another question, though...

One thing: Many people talk about "instances" of the Word application, when
they're actually dealing with only one instance, but multiple document windows.
I get the feeling you do know the difference, but it's important to be sure we
are talking about the same thing...

Cindy Meister
INTER-Solutions, Switzerlandhttp://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 orreply
in the newsgroup and not by e-mail :)

Have you experiemnted with command line switches like:
/n Starts a new instance of Word with no document open. Documents
opened in each instance of Word will not appear as choices in the
Switch Windows list of other instances.
or
/a Starts Word and prevents add-ins (add-in: A supplemental program
that adds custom commands or custom features to Microsoft Office.) and
global templates (including the Normal template) from being loaded
automatically. The /a switch also locks the setting files.
 
J

Jean-Guy Marcil

Cindy M. was telling us:
Cindy M. nous racontait que :
Hi Petr,


Yes, that could work. Especially since, if the user tries to start
Word, it should call that instance to the front. What happens if the
user then quits that instance and later starts a new one is another
question, though...

One thing: Many people talk about "instances" of the Word
application, when they're actually dealing with only one instance,
but multiple document windows. I get the feeling you do know the
difference, but it's important to be sure we are talking about the
same thing...

Exactly what I wanted to mention to Petr.
Also, if Petr stats a hidden instance of Word, it would good manner to make
sure he has a way of closing it as well.
 

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