.docx Versus .docm

With Word 2007 comes not one new format, but two—or four, depending on how you count:

  • .docx— An ordinary document containing no macros

  • .docm— A document that either contains macros or is macro enabled

  • .dotx— A template that does not contain macros

  • dotm— A template that either contains macros or is macro enabled

It is important for some purposes for users to be able to include macros not just in document templates, but in documents as well. This makes documents that contain automation a lot more portable. Rather than having to send both document and template, or worse, a template masquerading as a document, you can send a document that has macros enabled.

Note

When Word macro viruses first started appearing, ordinary Word documents could not contain macros—only templates could. Therefore, one of the most popular ways of “packaging” macro viruses was in a .dot file that had been renamed with a .doc extension. The virus itself often was an automatic macro (typically, AutoExec) that performed some combination of destruction and propagation when the rogue .dot file was first opened. A common precaution was to press Shift as you opened any Word file— .doc or .dot —to prevent automatic macros from running. In fact, even with various advances in security and antivirus software, pressing Shift when you open an unfamiliar Word document is still not being overcautious. In recent versions of Word, .doc files can legitimately contain macros, so I’m not really sure the situation has improved much. I still reach for the Shift key, do a quick inspection to determine whether any macros are hiding inside, and then proceed. Often, though, Word 2007 will warn you when a document contains macros.


Because Word 2003 documents can contain legitimate macros, there is no outward way to know whether any given .doc document file contains macros. If someone sends you a .doc file, is opening it safe?

While it’s not clear that the new approach—distinct file extensions for documents and templates that are macro-enabled—is going to improve safety a lot, it does provide more information for the user. This is true especially in business environments, where people don’t deliberately change file extensions. If you see a file with a .docm or .dotm extension, then you know that they contain macros and might warrant careful handling.

Moreover, if the document filename extension has been deliberately changed, Word will refuse to open the document. Whether it’s a .docx file that’s been renamed to .docm, or vice versa, you will see the message box shown in Figure 4-13.

Figure 4-13. Word 2003 refuses to open a .docx or .docm file when the filename extension has been deliberately changed.


Converting a .docx file into a .docm

If you want to convert a .docx file so that it can contain macros, you must use Save As and choose “Word macro-enabled document (*.docm)” as the file type. You can do this at any time—it doesn’t have to be when the document is first created. You can also remove any macros from a .docm file by saving it as Word document (*.docx).

Even so, you can create or record a macro while editing a .docx file, and even tell Word to store it in a .docx file. There will be no error message, and the macro will be available for running in the current session. However, when you first try to save the file, you will be prompted to change the target format or risk losing the VBA project. If you save it as a .docx anyway and close the file, the macro will not be saved.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset