Design Mode in Word 2007 and Word 2010: How to detect it and turn it on and off

Word 2007 and Word 2010 have a 'Design mode' button on the Developer tab. It's used to edit content controls.

As a developer, I may want to

  • know whether the document is in design mode
  • turn design mode on or off (for example, I would want to ensure that design mode is off before running any code that changes any content controls).

To the extent that I'm aware of, here's how.

Is the document in design mode?

The FormsDesign property of a document will tell you whether the document is in design mode. For example:

If ActiveDocument.FormsDesign Then
    MsgBox "This document is in Design mode"
End If

But this property does not work from VBA in Word. It only works if you are automating Word from outside Word, for example running a VSTO solution, or a COM add-in in VB6, or running VBA from Excel.

When Word 2007 was first released, there was a workaround for VBA using the old, hidden, deprecated Control Toolbox command bar. Control ID 1605 is the first control on the old "Control Toolbox" command bar. The following function returned the state of the active document:

Function IsDocInDesignMode () As Boolean

Dim cbc As CommandBarControl

    Set cbc = Application.CommandBars.FindControl(ID:=1605)
    IsDocInDesignMode = cbc.State

End Function

However, that workaround no longer works in a fully-updated installation of Word 2007. And it does not work in Word 2010. Not only does it not work, merely reading the .State property of the button will turn off design mode!

So as far as I can see, there is no way to know from Word VBA whether a document is in design mode.

Turning design mode on or off

There is no command in the Word object model to turn design mode on or off. We can toggle the mode with ActiveDocument.ToggleFormsDesign. So from outside Word, we could turn off design mode using something like the following:

If ActiveDocument.FormsDesign Then
    'Turn off design mode
    ActiveDocument.ToggleFormsDesign
End If

But if you are running code in Word VBA, you can toggle the design mode state, but you have no idea whether it will turn design mode on or off.