|
|
|
date: 3 May 2006 07:01:48 -0700,
group: microsoft.public.word.vba.addins
back
Re: How to suppress save template prompt (Word COM Add-in)?
wrote in message
news:1146664908.395594.120680@u72g2000cwu.googlegroups.com...
> Hi,
>
> I've written a COM Word add-in that adds a toolbar on connection and
> removes the toolbar on disconnection events.
>
> I've seen this topic already discussed in this group, and I learned
> that the best practice is to supply an additional global DOT file that
> will contain the toolbar, and the COM addin will simply load/unload
> that global template.
>
> This works just fine until I want to change something in the toolbar at
> runtime. For example, I'd like to disable (gray) some buttons when
> there are no open documents and enable it back again when there is one.
>
> The problem is that such operations modify the global DOT file and the
> "save mytemplate.dot?" prompt shows up when the user closes the Word
> application.
>
> The first solution is to reset the .Saved flag of the template to True
> after each such modification. And it works just fine.
>
> However, it conflicts with the case when the user has legally modified
> my toolbar (e.g. added a button to it via Tools->Customize). I wish I
> could ban such customization but I obviously can't.
You can't prevent the user from doing such modifications, but you can
prevent them from being saved. Ensure that the Saved property is set to True
whenever the template is unloaded. You can do this in code within your COM
add-in whenever it commands the template to unload. But you can and should
also include an AutoExit macro within the template itself. A macro titled
AutoExit automatically runs immediately prior to a global template being
unloaded. Therefore, setting the Saved property to True there will make it
most unlikely to be saved if the user attempts to unload the template by
hand.
As a further protection, you can set the template file to be read-only, so
that in the unlikely event that the user tries to force a save of the
template, the original will not be affected and the user will be prompted to
save a copy under a new name somewhere.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
date: Wed, 3 May 2006 15:25:39 +0100
author: Jonathan West
Re: How to suppress save template prompt (Word COM Add-in)?
> Unbelievable, it works exactly like you expected! :) Thanks!
>
Thank you for confirming that it does :-)
> The only question left to decide - is it really a good practice to
> prohibit the user from customizing my toolbar/menu or let it follow the
> standard "intuitive" behavior and write a load of code for correct
> handling of such modifications... What do you think?
>
I don't see any problem locking out your tools. If I were concerned that
the user might think there's something wrong with Word, I'd put them in
my own toolbar / menu, not "borrow" one of Word's. Then I'd lable these
so that it's clear enough they belong to my "tool". If a user asks, you
can certainly say, "Sorry, the tool is locked against modifications". Any
really determined user can remove the protection as simply as you've
added it, but "the average joe" won't worry about it.
> P.S. BTW can several versions of Office be installed on a single OS,
> for testing purposes? I'm afraid no, due to the common files.
>
I used to do this. But since discovering VMWare and the "virtual
machine", I simply set up a VM with the OS and software I'm developing
for :-) It's an investment I've never regretted.
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 :-)
date: Fri, 05 May 2006 15:24:02 +0200
author: Cindy M -WordMVP-
Re: How to suppress save template prompt (Word COM Add-in)?
wrote in message
news:1146767008.071985.227270@e56g2000cwe.googlegroups.com...
>
> P.S. BTW can several versions of Office be installed on a single OS,
> for testing purposes? I'm afraid no, due to the common files.
>
I would recommend not trying to do this. Not because you can't make it work.
Except for limiting yourself to a single version of outlook, you can
persuade different office versions to coexist. But it is not a remotely
realistic setup for other users, and if you are going to be making tools &
add-ins for other users, you want to be able to test under the most
realistic conditions practicable.
If you have a subscription to MSDN, one of the disks includes a copy of
VirtualPC. Dig it out and set up a separate virtual machine for each version
of Office you want to support.
If you don't have MSDN, then you can get VirtualPC or VMWare, both of which
do a similar job.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
date: Fri, 5 May 2006 15:36:21 +0100
author: Jonathan West
Re: How to suppress save template prompt (Word COM Add-in)?
oleg.krupnov@gmail.com was telling us:
oleg.krupnov@gmail.com nous racontait que :
> Hi,
>
> I've written a COM Word add-in that adds a toolbar on connection and
> removes the toolbar on disconnection events.
>
> I've seen this topic already discussed in this group, and I learned
> that the best practice is to supply an additional global DOT file that
> will contain the toolbar, and the COM addin will simply load/unload
> that global template.
>
> This works just fine until I want to change something in the toolbar
> at runtime. For example, I'd like to disable (gray) some buttons when
> there are no open documents and enable it back again when there is
> one.
>
> The problem is that such operations modify the global DOT file and the
> "save mytemplate.dot?" prompt shows up when the user closes the Word
> application.
>
> The first solution is to reset the .Saved flag of the template to True
> after each such modification. And it works just fine.
>
> However, it conflicts with the case when the user has legally modified
> my toolbar (e.g. added a button to it via Tools->Customize). I wish I
> could ban such customization but I obviously can't.
>
> A valid response to such situation would be to ask if the user wants
> to save the modified template when the application is shut down, but
> the above technique (.Saved=True) interferes with this requirement in
> many ways.
>
> Does anybody know a workaround? This should be a common problem, so
> there should be the best practice of providing custom toolbars in
> add-ins, on this level of detail?
Here is what I have done when I needed to allow users to save the template
if they made changes, but I was making changes on the fly as well.
So, basically, I know we are not "supposed" to do this, but any way, here
goes...
I set up a global Boolean flag. I set it to True on loading (there were no
changes so the template does not need to be saved).
Then, whenever I programmatically make a change that does not need to be
saved, I check my flag and the .Saved status *before* making my changes. If
they are the same, no problem, when I am done with my changes, I leave my
flag to True and change .Saved to True.
If, before doing my changes, the .Saved status was False but my Flag True
then the use made some changes of its own. I change my flag to False and I
do not reset the .Saved status (I made some changes, but so did the user...
so I do not change the Saved status). So when I next do changes, My flag is
False and so is the saved status. This way, I can tell if the template was
changed by the user because the only way to have my Flag set to False is
when I do changes. Basically, as soon as my Flag becomes False, I stopped
setting the .Saved property back to True after I do changes.
But this will work only when you rest your temporary customization whenever
a document is opened, otherwise, your changes are saved along with the
user's, and that is not good if you are not resetting everything to its
default status when opening documents.
I do not know if this makes any sense... It is a while since I have done
this and I might be forgetting something important... I hope I am not...
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
date: Fri, 5 May 2006 18:45:13 -0400
author: Jean-Guy Marcil NoSpam@LeaveMeAlone
|
|