Save document as .doc not .dot

M

Mona-ABE

How can I force a document to always save as a .doc? Currently, when people
use my automated document and they do "save as" the dialog box defaults to
..dot. If they inadvertenly save as a .dot, all the vba code behind the doc
gets dropped!
 
D

Dawn Crosier, Word MVP

You could force the template to always open as a .doc which would mean that
it should SaveAs as a .doc.

I insert this in my Templates when I am concerned about how a template gets
used:

Private Sub Document_Open()



'this code is for template and prevents

'the user from accidentally opening template

'in development mode...create standard document



'turns off repagination and screen updating

'to allow automation to work faster and

'less chance of template corruption or crashing



Options.Pagination = False

Application.ScreenUpdating = False



Dim intDocumentType

Dim strTemplateName As String

Dim strTemplatePath As String



'The following allows the entire project

'to know which template is being worked with

'and it's path. This prevents from having

'to place the template in a specific

'Word template directory. Both are Globals



'gets the full path/name of the active template

strTemplateName = Templates(1).FullName



'gets Path to Template and pads with "\" if required

strTemplatePath = Templates(1).Path

If Right(strTemplatePath, 1) <> Application.PathSeparator Then

strTemplatePath = strTemplatePath & Application.PathSeparator

End If



intDocumentType = ActiveDocument.Type



'*******************************************

'COMMENT OUT ALL INDENTED CODE BELOW WHEN WORKING

'ON TEMPLATE IN DESIGN MODE OR CHANGES

'WON'T BE PROPERLY SAVED. TURN IT BACK ON

'FOR FINAL SO USER CAN'T ACCIDENTALLY

'ACCESS MASTER TEMPLATE DESIGN

'********************************************



If intDocumentType = 1 Then

Documents.Add Template:=strTemplateName

Documents(strTemplateName).Close
SaveChanges:=wdDoNotSaveChanges

End If



End Sub


--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message was posted to a newsgroup, Please post replies and questions
to the group so that others can learn as well.
How can I force a document to always save as a .doc? Currently, when people
use my automated document and they do "save as" the dialog box defaults to
..dot. If they inadvertenly save as a .dot, all the vba code behind the doc
gets dropped!
 
J

Jean-Guy Marcil

Dawn Crosier, Word MVP was telling us:
Dawn Crosier, Word MVP nous racontait que :
You could force the template to always open as a .doc which would
mean that it should SaveAs as a .doc.

I do not understand why users are opening a template instead of creating a
doc from the template, as is the normal behaviour...

Anyway, I have never had the need to use code like the one you posted, so I
maybe way off base here, but one thing strikes me as peculiar:

The line
'gets Path to Template and pads with "\" if required
strTemplatePath = Templates(1).Path
will not always return the name of the template that was just opened.
It will return the name of the first loaded template in the template
collection, which includes all templates in the start-up folder...

But,
strTemplateName = ThisDocument.FullName
will return the template on which the current document is based, or the
template itself if the template is actually open.

Have I missed something?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Dawn Crosier, Word MVP

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.

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.)

Does that help?

--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message was posted to a newsgroup, Please post replies and questions
to the group so that others can learn as well.
Dawn Crosier, Word MVP was telling us:
Dawn Crosier, Word MVP nous racontait que :
You could force the template to always open as a .doc which would
mean that it should SaveAs as a .doc.

I do not understand why users are opening a template instead of creating a
doc from the template, as is the normal behaviour...

Anyway, I have never had the need to use code like the one you posted, so I
maybe way off base here, but one thing strikes me as peculiar:

The line
'gets Path to Template and pads with "\" if required
strTemplatePath = Templates(1).Path
will not always return the name of the template that was just opened.
It will return the name of the first loaded template in the template
collection, which includes all templates in the start-up folder...

But,
strTemplateName = ThisDocument.FullName
will return the template on which the current document is based, or the
template itself if the template is actually open.

Have I missed something?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Dawn Crosier, Word MVP was telling us:
Dawn Crosier, Word MVP nous racontait que :
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 problems come up, but I see that it cold
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 frist tempalte in the collection is the the attached
templte to the current docuyment being opened.

Normnally, that works ok.

For example, let,s imagine this situation:
1) A user opens the special template (CodeTemplate) that has this code, the
code works as expected and a Document1 is crerated.
2) Next, let's say another template (not Noraml.dot, let's call it
NoCodeTemp) is opened. Now, this second temaplte (NoCodeTemp) is the first
one in teh tempalte collection. We now have Document1 based on CodeTemplate
opened and a temaplte called NoCodeTemp opened.
3) If the user now decides to open again CodeTemplate, the code executes.
But becasue NoCodeTemp is now the frist in teh tempalte collection, what we
get is this:
Document1 based on CodeTemplate opened, CodeTemplate is opened (it never
got closed by the code because NoCodeTemp was closed intead) and Dopcument2
is operned, but it is based on NoCodeTemp whjich is still the first tempalte
in teh collection.

If, at tstep number 2), the user creates a document bsed on a NoCodeTemp
instead of opening it, then at step three you get an error message on
Documents(strTemplateName).Close SaveChanges:=wdDoNotSaveChanges
--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

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
 

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