Word Document SaveAs default file extension is .DOCX

J

Jon Robertson

When using the Word Document SaveAs method in Word 2007, and using
wdwdFormatDocument (or wdFormatDocument97, they are the same) but not
specifying a file name, Word saves the document in 97 format but with the
..DOCX extension.

When you later try to open this document in Word 2007, Word complains that
it experienced an error trying to open the file.

If a filename is not provided to SaveAs, it seems that the file extension
used should be based on the FileFormat specified.

Also, it seems that Word should be smart enough to recognize a native Word
file even if the extension is wrong. If the internal format is 97-2003, then
open it in Compatibility mode. If the internal format is 2007, open it in
2007 mode. I'm surprised that Word is relying on the document extension to
determine the format of the file.

--
Jon Robertson
Borland Certified Advanced Delphi 7 Developer
MedEvolve, Inc
http://www.medevolve.com

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/communitie...=microsoft.public.office.developer.automation
 
J

Jialiang Ge [MSFT]

Hello Jon,

From your post, my understanding on this issue is: you want to know why
Word 2007 saves the document with .docx extension when the parameter
FileFormat of Document.SaveAs is wdFormatDocument (doc) and FileName is
left blank. You also wonder why Word 2007 cannot open a docx file whose
file format is wdFormatDocument (doc). If I'm off base, please feel free to
let me know.

According to the MSDN article
http://msdn2.microsoft.com/en-us/library/bb221597.aspx, if the parameter
FileName is not specified, Word 2007 uses the current default file name.
(1) If it is a new document which is never saved before, by default,
documents in the 2007 Office release are saved in XML format with new file
name extensions that add an "x" to "doc". Therefore, you may find that
"ThisDocument.SaveAs FileFormat:=wdFormatDocument" creates a new file
"Doc1.docx" with old doc format in your default SaveAs directory, such as
"My Document". (2) If the file has been saved (for instance, Doc1.docm),
and you open it, then call "ThisDocument.SaveAs
FileFormat:=wdFormatDocument", it will overwrite the original file
(Doc1.docm) with doc format because the current default file name is
Doc1.docm. This is a behavior by design. If you do feel it is not an
expected behavior of Word or it interferes with your development, I will
help to submit a request to Office Development Team for you. Besides, I
think we need to find a way to make sure the file is named correctly. Would
you give me a description of your program's context, so that we may find
some workarounds? I am looking forward to your reply.

For your second question about opening a docx file whose file format is
doc: Word 2007 decides the file type either by its file extension or by the
file signature (the first 4 bytes of the file). Because the file signature
is sometimes far from a perfect method, and Windows file system itself
provides no information about a file's type, Word 2007 is mainly depending
on the file extension. That is why, sometimes, Word 2007 is not able to
open the file with incorrect extension.

Please let me know if you have any other concerns, or need anything else.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jon Robertson

From your post, my understanding on this issue is:

You understood both of my points correctly.
(1) If it is a new document which is never saved before, by default,
documents in the 2007 Office release are saved in XML format with new file
name extensions that add an "x" to "doc".

I understand current behavior. I was posting a suggestion that the current
behavior should be changed in a future update or version. The default
filename should use an extension that corresponds with the document type
specified. I never noticed this before, because I was previously always
saving to the default document type, so the default extension was "correct".
I only noticed the behavior because with Word 2007, I am not saving to the
default document type.
Besides, I
think we need to find a way to make sure the file is named correctly. Would
you give me a description of your program's context, so that we may find
some workarounds? I am looking forward to your reply.

Now that I've discovered this behavior, I can easily work around it.
However, I spent a couple of hours trying to figure out what was wrong with
my code, since I could not get Word 2007 to save in the .doc format via the
Automation library. Once I determined that the file was the correct format,
Word had just given it the wrong extension (based on document type), I knew
how to change my code to correct the situation.
Word 2007 decides the file type either by its file extension or by the
file signature (the first 4 bytes of the file). Because the file signature
is sometimes far from a perfect method, and Windows file system itself
provides no information about a file's type, Word 2007 is mainly depending
on the file extension.

I would expect the file signature for *.doc files to be fairly consistent.
I would also expect Word to be able to detect a *.doc file based on its
signature, regardless of the extension.

I would not expect the same behavior when Word tries to open foreign files
(files that are not standard Word files, such as .doc, .docx, .dot, .dotx,
etc).

Again, both of my items were suggestions for changes. I consider them both
to be defects. Perhaps not bugs, in that Word is doing what Microsoft
intended. But certainly design defects.

Jon
 
J

Jon Robertson

Please let me know if you have any other concerns, or need anything else.

Here is the bottom line. When you take both of these issues into account,
you get the following behavior:

Use the Document object to save a new document with "ThisDocument.SaveAs
FileFormat:=wdFormatDocument". Now close the document and try to open the
newly saved file in Word 2007. Word 2007 can't open it.

I consider that a bug. I consider the correct fix is to change the behavior
of SaveAs.

Thanks
 
S

Steve Rindsberg

Word 2007 decides the file type either by its file extension or by the
I would expect the file signature for *.doc files to be fairly consistent.
I would also expect Word to be able to detect a *.doc file based on its
signature, regardless of the extension.

I'm guessing that the inability (or rather refusal) to open files where the
extension and signature don't match is deliberate or a side effect of other
security measures.

For example, a real DOC file might contain macros.
Office 2007 apps insist that files which contain macros have a .---M extension
A file with a DOCX extension but that's in a format that may contain macros
could be a security threat, an attempt to spoof Word into allowing a macro to
run when it shouldn't.
 
J

Jialiang Ge [MSFT]

Dear Jon,

Thank you so much for your great suggestion. I believe that other community
members will also benefit from your experience sharing. Without the input
of numerous intelligent and warmhearted customers like you, our MSDN
Managed Newsgroup can never be as comprehensive and helpful as it is today.
I appreciate your time and efforts working with us.

As Rindsberg said, Word 2007 by design do not open a document that claims
to be a DOCX but in fact isn't (for security reasons). But for your
suggestion about the behavior of SaveAs when FileName is not specified, I
agree with you and I have filed a design request to the Office Development
Team. If they approve it, the behavior will be changed in the next version
of Office.

Thank you again for the suggestions. If you have any other comments on our
support service, website design, our product limitation, our process, and
etc., please don't hesitate to let me know. I will do my best to follow up.

Have a nice day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

MattH

If Word will not open a .doc file renamed to .docx as a security measure,
since the .doc file could contain macros, will it work to rename the .doc
file to .docm?
 
J

Jialiang Ge [MSFT]

Hello MattH,

If .doc with macro were renamed to .docm, Word 2007 would still not able to
open it. However, based on my tests, Word 2003 with Office Compatibility
Pack for Word 2007 File Formats is capable of opening the docm or docx
whose real format is doc. All in all, Office 2007 expects all the files
with docx/xlsx/pptx extension can be unzipped. If it fails to extract the
file, an error "Word experienced an error trying to open the file" will be
popped up.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
D

damu maddy

Hi friends

I am new bee to this tech

I am trying to Override the "Save as" functionality in Word 2003



I am using word add-in ,vs.net 2005 professional edition

I got help to create menu in the word programatically



I created a 2003 Add-in --------->Word Add-in project



Using this help

http://msdn.microsoft.com/en-us/library/0batekf4(VS.80).aspx

I created a custom menu in the Word ,and opened a save as dialog box in the
event handler of the custom menu



I need to know how to override the default functionality of "Save as " in
the Word

Because ,When the user hit the "Save as" menu I want to get the name
entered in the File name Text box of Save as Dialog Box ,When the File is
saved and display it in message box



Please direct to the link where can find the help
 

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