Word for Mac Content Control Add-in

After 15 years, I got tired of waiting for Microsoft to provide Content Controls in Word for Mac. So I wrote a VBA add-in to do it. The Word for Mac Content Control Add-in is free if you subscribe to this blog. There’s no installer (Apple’s sandbox requirements for automatic installation are onerous.), but I provide installation instructions.

Content Controls are a superior way of creating forms, easier to create and use then the Legacy Form Fields that are built into Word for Mac. In a previous post, I’ve written about how you can insert content controls using VBA: Content Controls for macOS – Cool Code. But using VBA requires more technical ability than the average Word user has. So writing an add-in makes these controls available to a much wider group of users.

The new content controls appear on Word’s Developer tab:

Developer tab showing Content Controls

The Properties button opens a dialog that allows you to set the items relevant to that type of control:

The Properties dialog


Current issues with this Content Control add-in:

  • In Word for Windows, you can set a separate character style for the control. The VBA commands for sorting styles don’t do the same thing as the Word interface, so I haven’t been able to make this work the same as in Windows. Using my Content Control add-in, the content controls currently take on the style of the paragraph in which they are inserted, except for the Date Picker which displays Times New Roman (?!) when a date is selected.
  • The color for a control can be set to the same colors as in Windows, but there isn’t a custom color input yet.
  • If and when Microsoft gets around to adding content controls, the checkbox will probably select checked and unchecked characters from the macOS Emoji & Symbols dialog. Unfortunately, that dialog includes many system fonts that can’t be embedded in a file (this is a big problem with choosing bullets in PowerPoint, but that’s material for a different article). So I’ve created a subset of checked and unchecked symbols that can be used in checkboxes. These characters will work as expected and can be embedded in a template or document.
  • The properties dialog in the Content Control add-in can’t preview the checkbox characters, because there is no way for VBA to retrieve the symbols currently used by a checkbox.
  • The date picker should be able to use a world-wide variety of locales and calendar types. I haven’t been able to program the system calls to macOS to get this information yet. The date picker currently uses U.S. defaults for date formatting. Using Microsoft date formatting codes (dd-mm-yyyy, etc.), you should be able to set up dates for other languages based on a Latin (Western) script. This is one of the items that needs testing in other languages.
  • A known error occurs if you try to insert a Content Control into an old Word file in .doc format. You’ll see an error like Run-time error 445: Object doesn’t support this action. Update the file to .docx format to fix the issue.
  • A few users get error messages when trying to modify existing content controls. To date, we have not been able to reproduce, and thus solve, this bug. If you get an error, please post a comment including your processor info (Intel or Apple chip), macOS version and Office edition.

You can get a free copy of the add-in by subscribing to this blog. If you’re already a subscriber, please write to me at the email in the right-hand column, and I’ll send it to you. Please note, we do not send to disposable email addresses.

Edit OOXML with VBA – Cool Code

For Office users, the closest thing to a “programming language of the people” is VBA. It’s not too hard to get started, there are gobs of help information from a good search, and the results are immediate. But VBA’s abilities haven’t expanded as its environment has changed. This has become abundantly clear with current versions of Office, where task panes and the Windows-version Backstage haven’t been included in the VBA object model. Many want to edit OOXML with VBA, but Microsoft prefers to shuffle you off to the Open XML SDK programmed with C# to do that job.

Fortunately, we’re on the case at Brandwares. We collaborated with programmer Jan Karel Pieterse to develop a PowerPoint version of his macro set that edits Excel OOXML. We’re making this freely available as a download so you can get the benefit of this.

Let me apologize to my macOS readers. I really try to provide solutions that work cross-platform, but this macro set relies on Windows system calls.

I’ll be honest, this isn’t the most elegant OOXML editing solution. The macro set unzips the OOXML to its component files, gives you the opportunity to edit the XML using VBA string manipulation, then rezips the OOXML to a usable PowerPoint file. The unzip/rezip operations are fairly slow, especially with large files. It’s not something you can use in a real-time editing situation.

One of Brandwares’s specialties is converting legacy presentations to new themes/templates. Often, there are OOXML mismatches that make reused slides retain artifacts or formatting from the old decks. We solve these issues with macro convertors that take a folder full of old decks and transform them into new presentations with new branding. This macro set is great for that.


Edit OOXML with VBA: a Peek Under the Hood

THe file contains 3 VBA modules and 1 class module. Module modConvert is the only one you need to modify. In it, Sub MainVBAOperations does the actual work of opening files, saving as a work file, calling the XML process, saving the modified file and deleting the work file. This is also where you would do any additional VBA processing. As one example, after you modify the XML of a slide master or layout, you have to reset the slide based on it to display the changes. MainVBAOperations is where you would do this.

The other Sub is ProcessXML. Here’s where you unzip the file being modified, open different XML parts for find and replace processes, followed by a rezip of all files back to a working file. The sample code in this module shows a typical revision to the idx numbers of placeholders, a common requirement of legacy presentation conversions and one that can’t be done with the PowerPoint interface.

The module modDisplay, by Shyam Pillai, provides the PowerPoint equivalent of the Application.Screenupdating command that exists in Word VBA. Useful to prevent the screen flashing and jumping as files are processed, it also helps speed code execution. modUNC by Randy Birch, assists with file management.

Jan Karel Pieterse wrote the class module clsEditOpenXML that does the heavy lifting of unzipping and rezipping the document to be modified and reading and writing the XML.

As noted in the code, You are free to use this code within your own applications, add-ins, documents etc but you are expressly forbidden from selling or otherwise distributing this source code without prior consent. This includes both posting free demo projects made from this code as well as reproducing the code in text or html format.


Converting Legacy Presentations

We use often use this macro set to update old (legacy) presentations with a new design. Successful updating requires meeting 5 criteria, please read this article for more details: Legacy Slides – Best Practices. As noted on that page, the 5th requirement is that placeholder idx numbers in the OOXML must match on the old and new layouts. There’s nothing in PowerPoint’s interface that allows you to set idx number, but this macro set allows you to do just that. The pre- and post-processing sections of the macros allow you to set the the other 4 parameters for each slide layout. Click here to download it.

The following advice is particular to presentation conversion. It’s routine that slide masters and layouts will be changed in that process. Then, to apply those changes to the actual slides in a presentation, the slides must be reset, as if you pressed the Home>Reset button in a presentation. Resetting slides wipes out character-based formatting. If a user has applied bold or italic or an underline to particular text, that all will disappear. It’s important to notify your client of this. To make an exact update would require a painstaking construction of a multi-dimensional array for each placeholder on each slide that would record all character-based formatting, then restore it after the update, for which you would have to charge many times as much as for the basic conversion work.

Brandwares is a world leader in presentation updating and conversion. We’re available for presentation assessments, to identify potential problems. We have multiple techniques for seamless re-use of legacy presentations. Contact us when you’re redesigning to ensure your new template will reuse your old slides without a hiccup.

Office Automation with AppleScript Reference – Cool Code

For Office for Mac users, AppleScript remains a useful tool in scripting Office documents. VBA for Mac has poor links to the operating suystem. In Windows, a programmer can easily make system calls to the OS. In macOS, the analogous system calls are not documented by either Apple or Microsoft. A few intrepid programmers have posted about macOS equivalents, but the information is sporadic and very hard to find. macOS’s built-in AppleScript can solve many of these issues, so I’m posting the best available Office AppleScript Reference.

This is old Microsoft documentation from 2008 that they’ve removed from their site. I don’t guarantee this, or offer support, I’m just posting it to make it available to interested programmers.

Office AppleScript Reference: MacScript vs AppleScriptTask

Ron de Bruin is a European programmer and MVP (Microsoft Valued Professional) who has written lots of good information about programming Office on a Mac. While he writes mostly about Excel, VBA is so similar across Office that most of the information also applies to Word and PowerPoint. Here’s his page on using the AppleScriptTask command in Office 2016 and later to call AppleScripts from a VBA macro: AppleScriptTask in Mac Office 2016 or higher.

Office AppleScript Reference: Conditional Compilation

To create a macro that can run on different versions of Office for Mac, or on both Windows and Mac, you’ll need to use conditional compilation. This uses #If – #Else – #End if statements to run a set of commands only in certain conditions. Here is Microsoft’s page on conditional statements for different Mac versions: Differentiate between Office for Mac versions at compile time. This MS reference page shows all available conditional compiler constants: Compiler constants.

Click here to download: Office AppleScript Reference.

Another useful reference for AppleScript automation of Office is the online article Moving from Microsoft Office VBA to AppleScript by Paul Berkowitz. This is a full-length book with comparisons between VBA and AppleScript, plus many real-world example scripts. It was originally published in 2007, in anticipation of Office 2008. Unfortunately, the downloadable PDF they promise is no longer available.