An OpenXML Word 2007 Document in Visual Studio 2008 showing customUI.xmlAnd to further contradict my previous rants, it is possible to write a macro to load Word Document Parts. However, none of these contradictions hold comfortable solutions. First, you can see the XML file, customUI.xml, in my Normal.dotm template. All I had to do was to edit this file to customize the Word 2007 “Fluent” Ribbon. This is what I did:

  1. Use the Custom UI Editor Tool to generate the proper OpenXML parts in the Normal.dotm template to get me started writing raw XML against the Word 2007 application. I could have done this by hand using the tool mentioned in step 2 but was too “lazy.”
  2. Use the Open XML Package Editor in the VSTO 2008 Power Tools to write raw XML. Doing this in Visual Studio was easier on my eyes (larger, bolder fonts than the Custom UI Editor Tool) and I could use the customUI.xsd schema (in 2007 Office System: XML Schema Reference) to make writing faster (Intellisense support). Also I found out the hard way that it is better to write this XML in a separate file in case Word panics and auto-magically deletes all of my hard work! Visual Studio is a great XML file editor.
  3. Use the 2007 Office System Document: Lists of Control IDs to wade through the sea of “Fluent” fluxions. Utterly ridiculous but it helped.

Okay: and now the macro thing. This is the important call in the important line of code that makes loading Quick Parts (or Custom Quick Parts) automatable: Call Application.NormalTemplate.BuildingBlockEntries.Add(). So what’s my problem? The problem is that a Range containing my custom XML does not get saved properly. Sometimes elements named “unknown” come out from the Quick Part Gallery. You don’t understand what I am talking about? I can sympathize. It would take days upon days to explain to a Microsoft employee—even one on the Word 2007 team—what the hell I am talking about… My guess is that this “edge case” will be fixed by accident in a future release.

And, speaking of Microsoft employees, here’s a table of resources researched for this crap I am writing:

Reuse and distribute parts of a document This was first document that explained to me how to build a Building Block. “Building blocks are reusable pieces of content or other document parts that are stored in galleries.”
Office 2007 “Legacy’ Mode In case I want to admit that I can’t handle change: “No, it’s not really a secret setting. It’s an add-in for Office 2007 that will finally give IT admins relief from that one user who resists change in all possible forms.”
Customizing the Office 2007 Ribbon Somehow Word MVP, Bill Coan, wrote an article that misled me into thinking you could not customize the Word 2007 Ribbon without paying for it. Surely, that’s my fault…
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3) Frank Rice and Ken Getz: “Learn how to customize the 2007 Office Fluent user interface. Also learn how new features in Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System support RAD development of Ribbon customizations. (40 printed pages)”
Mapping Word 2007 Content Controls to Custom XML Using the XMLMapping Object

This article really has nothing to do with the Ribbon but is related to “custom XML”: “Office Word 2007 has no user interface (UI) to map controls to XML with one exception—SharePoint and Built-in properties listed in the Quick Parts | Linked Properties menu.”

My point? Developer tools are increasingly becoming more important (to me) for Word. It is not healthy to regard Microsoft Word as “the people’s” word processor.

XML: The Angle Bracket Tax A Jeff Atwood diversion: “XML is like democracy. Sometimes it even works.” I commend Microsoft for attempting to XML-lize a word processor, but working with this is still not fun… :: The wide world of Linux word processors This is a subtle admission that reading fonts comfortably in a Linux-based “free” word processor is not the greatest: “The font rendering in TextMaker is a thing of beauty, and is noticeably superior to the other programs in this review.”
How to: Create a Custom Building Block Gallery This is the article that showed that you can write a macro to load a Building Block.
Microsoft announces Open XML SDK roadmap When Microsoft writes about “[a] content object model including additional classes and methods for simplifying developer work within parts…” this responds directly to my GetStream() concerns in a previous entry.

Every time I write a post about Microsoft Word, I feel obliged to explain why I am still using Microsoft Word:

  • The concept of inserting custom XML elements directly into prose is not even recognized in
  • The visual comfort of viewing type written by hand for hours at a time is an issue that (and others) struggles with… and I am not able to go along with that struggle. Microsoft has ClearType and Bill Hill.
  • The .NET programmability of Word 2007 allows me to treat prose like data. My work on CleanXHTML 1.2 is an attempt to realize this advantage. No one on this planet (including Microsoft) seems to popularize the importance of fluidly moving between loose prose and tightly defined data. This motion should have the same sexiness that dynamic programming languages seem to have with self-described geeks. On the Mac, there is a word processor called Scrivener that treats blocks of prose like DOM nodes. This is the sexiest example of what I am talking about that I can find at the moment.

Okay: my verdict for the famous Ribbon, featured in the “Fluent” user interface:

  • There is a Word MVP selling a Ribbon Customizer for 30 bucks. So for those wanting make jokes out of all conspiracy theories here is a new funny one: Microsoft, a multi-billion-dollar enterprise, conspired to release a new user interface that is not customizable so that one of their MVPs can make some money, 30-bucks a pop.
  • At MIX08 some dude from Microsoft spoke for about an hour about the “innovative” history of the Ribbon but failed (according to my attention span) to mention the obvious: you can’t customize the Ribbon! To not even apologize for this and promise to fix this in a future release is outrageous—like Steve Jobs outrageous.

Okay: my new understanding of the SDK for OpenXML:

  • No more shall the SDK for OpenXML be confused with the Word 2007 Content Control Toolkit.
  • The strong word “Part” used throughout the OpenXML API, starting with the abstraction OpenXmlPart, represents a location in the ZIP OpenXmlPackage. In the same manner that an XML document contains nodes (or a database store contains tables), an OpenXML Package contains parts. The OpenXmlPart, as of today, does not define anything (useful to me) inside of an XML file.
  • The SDK for OpenXML APIs do not define anything of significance inside of an XML file. This is most important piece of information I need about this SDK. It follows that the OpenXmlPart.GetStream() and OpenXmlPart.FeedData() methods are the most important members of the entire SDK for OpenXML. So, for example, silly me would be looking for a class called “DocumentPart” or (“GlossaryDocumentEntry”) in the OpenXML API which would correspond to the <w:docPart> element. As of today these types to do exist.

I would like to be very much mistaken about this but seems that to actually do something useful (to me) with this API, I would have to call WordProcessingDocument.MainDocumentPart.GlossaryDocumentPart.GetStream() and modify raw XML to, say, programmatically load AutoText (Quick Part) entries. This sucks. I can do it—but it sucks. (And, no, MVPs you can’t just run a Macro for Quick Parts.)

Speaking of conspiracy theories, I get a distinct feeling that Microsoft, with its billions of dollars, will never provide a clean API wrapper around the raw XML (based on a sick profit motive based on the idea that making high-fidelity content difficult to get out of Office documents keeps customers locked into Office products—yes, Brian Jones I am still saying shit like this even though the word “open” is in OpenXML)—even though this must be irresistible to some young Redmond new hire just itching to play with LINQ. Is some MVP out there going to charge US$499 for LINQ to OpenXML?

I thought it would cute to do a Google search with the keywords WordProcessingDocument and GetStream. Barely 40 documents in the entire wired universe showed up—all of them irrelevant. It’s lonely at the top.