Dawn Crosier, Word MVP was telling us:
Dawn Crosier, Word MVP nous racontait que :
Hi Dawn,
Please, disregard the other reply to this post of yours, if you see it at
all.
You won't probably be able to understand much of it anyways...
If this is the only reply you see, then all is well and an obscure OE
feature actually worked! If this is the case, I am impressed!
I tried to get it removed from the server,but I do not know if it will be
removed.
Anybody knows how to deactivate the &*?%$ CTRL-Enter in OE that actually
sends the message being written?
My typing is horrid and I always need a second or even third read to correct
all the typos my totally uncoordinated fingers produce.
I often do CTRL-Enter by accident when I mean to do SHIFT-Enter...
Jean-Guy -
There are times when people place templates on desktops or network
folders. In those cases it is not always possible to be sure that the
users will not perform a File / Open rather than a File / New / From
Existing. The code I provided protects the template from becoming
changed - when the user thought he/she was making a new document
based on the template.
Ha, got it now! Never had that problem come up, but I see that it could
happen...
Good point about the code change. (I got the code from Dian Chapman
and did not question it - I have used it successfully for several
years now, without thinking how it could become better.)
I did miss something...
I forgot that the first template in the collection is the attached
template to the current document being opened, or the template itself if a
template is being opened.
IOW, the first template in the collection is the last to be loaded...
Normally, that works ok.
There could still be unpredictable results.
For example, let's imagine this situation:
1) A user opens the special template (let's call it CodeTemplate) that has
this code,
the code works as expected and a Document1 is created.
2) Next, let's say another template (not Normal.dot, let's call it
NoCodeTemp) is opened. Now, this second template (NoCodeTemp) is the first
one in the template collection.
We now have Document1 based on CodeTemplate
opened and a template called NoCodeTemp opened.
3) If the user now decides to open again CodeTemplate (to create a second
document, the code executes a second time. But because NoCodeTemp is now
the first in the template collection, what we get is this:
Document1 based on CodeTemplate is still opened, CodeTemplate is opened (it
never got closed by the code because Templates(1), or NoCodeTemp, was closed
instead) and Document2 is opened, but it is based on NoCodeTemp which is
still
the first template in the collection.
If, at step number 2), the user creates a document based on NoCodeTemp
instead of opening the actual template, then at step 3) you get an error
message on
Documents(strTemplateName).Close SaveChanges:=wdDoNotSaveChanges
because strTemplateName points to NoCodeTemp which is not actually opened
because the user did File > New (or a double click) instead of File > Open,
and NoCodeTemp is Template(1) because there is an opened document based on
NoCodeTemp that was created after the document based on CodeTemplate.
If you replace Templates(1) by ThisDocument, you never get any unexpected
results or error messages similar to what I described above.
This is pretty twisted and chances are that this scenario will never happen,
but I guess it comes from my twisted mind which always over-think when I
write code...
I always write code for all potential errors I can imagine that could
happen, even if they are remote scenarios...
The proof that it is twisted is that you have used this code for years and
nobody has ever reported a problem, and I bet you would have been the first
to know if an error occurred or unexpected result were ever obtained!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org