Though I’ve done this automation in Delphi, this applies to automation from any development platform. In this particular project, the documents used Bookmarks. Those have changed over time, so has the Word support for it.
From Word 2000 until Word you could disable the showing of Bookmarks by setting the ShowBookmarks property to False like this:
<br />ActiveDocument.ActiveWindow.View.ShowBookmarks := False;<br />
Well, when doing this, Office 2013 can throw an error like this:
EOleException: The ShowBookmarks method or property is not available because this command is not available for reading
ErrorCode: 0x800A11FD
Source: Microsoft Word
HelpFile: wdmain11.chm
The full error message does not give any useful search results. But a partial search finds a Word 2013 issue towards the top of the results:
sometimes Words opens the document in Reading layout. Reading layout does not allow all operations in Word 2013.
If a document is protected, and you try to change something you should not, you get an error message like this:
This method or property is not available because the document is a protected document.
Usually, Cindy Meister is very accurate. However this time here code
...ActiveWindow.View = wdPrintView
should have been like
...ActiveWindow.View.Type = wdPrintView
Of course you also have to save/restore this property while you are enabling the ShowBookmarks property.
So you get Delphi code like this:
var CurrentView: View; OldViewType_: WdViewType; begin CurrentView := ActiveDocument.ActiveWindow.View; try CurrentView.ShowBookmarks := False; // Word 2013 might raise a EOleException: The ShowBookmarks method or property is not available because this command is not available for reading except on E: EOleException do begin if E.ErrorCode = $800A11FD8 then begin OldViewType_ := CurrentView.type_; try CurrentView.type_ := wdPrintView; CurrentView.ShowBookmarks := False; finally CurrentView.type_ := OldViewType_; end; end else raise; end; // E: EOleException end; end;
This probably gives similar errors in other mistakes when you want to alter the document in Office 2013: basically the wdReadingView mode is readonly, the wdPrintView is read-write.
Another solution is for all your users to disable the Reading View mode in Word 2013.
Below is a table with the relevant objects, properties and method documentation links for the various Office versions (documentation for Office XP and Office 2000 is not available any more):
Name | Value | Description |
---|---|---|
wdMasterView | 5 | A master view. |
wdNormalView | 1 | A normal view. |
wdOutlineView | 2 | An outline view. |
wdPrintPreview | 4 | A print preview view. |
wdPrintView | 3 | A print view. |
wdReadingView | 7 | A reading view. |
wdWebView | 6 | A Web view. |
wdConflictView=8 (documentation about it is very sparse)
–jeroen
Filed under: Delphi, Delphi XE2, Delphi XE3, Delphi XE4, Development, Office, Office 2000, Office 2003, Office 2007, Office 2010, Office 2013, Office Automation, Power User, Software Development, Word