The four Word Open XML extensions share one layout. They differ in the content type of the main part, and in whether the file may hold a macro project.
The four kinds
| Extension | What it is | Macros | Main part content type |
|---|---|---|---|
.docx | Document | No | application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml |
.docm | Document | Yes | application/vnd.ms-word.document.macroEnabled.main+xml |
.dotx | Template | No | application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml |
.dotm | Template | Yes | application/vnd.ms-word.template.macroEnabledTemplate.main+xml |
The macro-enabled content types are Microsoft’s own. Part 1 (11.3.10) lists only the two
non-macro main-document types. The viewer compares the file name’s extension with the content
type of the main part and reports a mismatch (for example a .docx name on a
.docm content type) as a problem on the overview.
MS-OI29500 2.1.527 gives the content types Word accepts for an altChunk part: the
four main-document types above, message/rfc822, application/xml,
application/rtf, application/xhtml+xml, text/html and
text/plain. It also gives the relationship type
…/officeDocument/2006/relationships/aFChunk.
The macro project
Macros are in the part word/vbaProject.bin, reached by a relationship of type
http://schemas.microsoft.com/office/2006/relationships/vbaProject from the main document,
with the content type application/vnd.ms-office.vbaProject.
The part is not XML. It is a Compound File (a small file system with storages and streams), in
the VBA project format that Microsoft documents as MS-OVBA, with the source of each module
compressed. Files that keep macro data for Word’s editing state may also have
word/vbaData.xml, and word/customizations.xml holds Word’s key
bindings.
The project’s own structure is in MS-OVBA. Under the VBA storage, the
dir stream (compressed, MS-OVBA 2.4.1) is a list of records: project information
(system kind, code page, name, help file, constants), then the references (2.3.4.2.2: name,
registered library, original library, control library, project), then the modules
(2.3.4.2.3: name, stream name, text offset, type, read-only and private flags). Each module
stream starts with an implementation-specific performance cache of exactly the text-offset size,
which readers ignore; the source follows, compressed, as text in the project’s code page. A
PROJECT stream holds the same project as text lines.
In the Apache POI sample SimpleMacro.docm, the project has ten streams: the
dir stream, two modules (Module1 and ThisDocument),
_VBA_PROJECT, four __SRP_ streams, PROJECT and
PROJECTwm.
The macro project has its own relationship to word/vbaData.xml
(…/2006/relationships/wordVbaData, content type
application/vnd.ms-word.vbaData+xml). That relationship starts from
vbaProject.bin, not from the main document. Its root is wne:vbaSuppData
with a wne:mcds list of wne:mcd entries; the sample holds one, with
the attributes macroName, name, bEncrypt and
cmg. Neither MS-OI29500 nor MS-DOCX describes this part, so what it means is not
documented here beyond what the file shows.
The viewer on this site lists the project’s fields, protection, references, modules (name,
kind, stream, size, source lines, flags) and every stream, and shows each module’s source as
text. It also shows the entries of vbaData.xml. It never runs, interprets or
compiles macros, and the p-code is skipped.
Customizations and toolbars
The Customizations part (MS-OI29500 3.1.1.2) holds the template command group: key mapping and
toolbar customizations. Its content type is application/vnd.ms-word.keyMapCustomizations+xml
and its relationship type is http://schemas.microsoft.com/office/2006/relationships/keyMapCustomizations.
A package has at most two: one reached from the main document and one from the glossary
document.
The Attached Toolbars part (3.1.1.1, content type application/vnd.ms-word.attachedToolbars)
is reached from the Customizations part. It is a single binary stream holding one CTBWRAPPER
structure, as specified in MS-DOC 2.9.49. The viewer names the part and does not decode that
structure.
In the Customizations part, each keymap binds a key to an action. A key is given
by kcmPrimary and kcmSecondary (a virtual-key code) or
chmPrimary and chmSecondary (a character); in both the left byte holds the
modifier flags. The action is a child: fci (a fixed command), macro,
wll, acd (an allocated command) or wch (a character to
insert). keymapsBad holds bindings for another keyboard. The viewer decodes the
keys and actions into a table, and lists the allocated commands.
Templates
A template is laid out in the same way as a document, with a different content type. When a
document is created from a template, the template’s name goes into the
w:attachedTemplate setting (by relationship ID) and the
Template application property. That relationship is usually an external path
or URL. MS-OI29500 2.1.385 says Word needs the relationship type
…/officeDocument/2006/relationships/attachedTemplate, and does not support a
val attribute on the element: the path comes from the relationship.
Building blocks (AutoText, Quick Parts) are held in a glossary document: a part
normally named word/glossary/document.xml, with its own styles, settings and
fonts, reached by a glossaryDocument relationship. Its root is
w:glossaryDocument, and it has a w:docParts list.
Part 1 (11.3.8) gives it the content type
application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml.
A package has at most one, reached by an implicit relationship from the main document. It may have
implicit relationships to comments, settings, endnotes, the font table, footnotes, numbering and
styles, and explicit ones to headers, footers, images, charts, diagrams, hyperlinks and the other
parts that 11.3.8 lists, and to no other parts.