1

The following code has caused me a lot of pain in my add-in for Word 2016:

_application.ActiveWindow.View.ReadingLayout = true;

The problem is that Word 2013 and Word 2016 appear to do different things with the above line of code.

Word 2013 will only apply that setting to the active window. Thus, when I open a different document, it will open in edit mode instead of reading layout. This is the behavior I want.

In Word 2016, the exact same line of code appears to set the ReadingLayout not only for the active window, but for every other window that is opened up after that setting is set (not for other open windows). Specifically, I'll open up a document, set the ReadingLayout to true, so that the active window changes to the reading layout, then I will open another document. Instead of opening in edit mode, it too opens in the reading layout.

Even if I close and re-open Word, all documents that are opened through Word will open in Reading Layout until I manually go and change the layout.

My question is this: Is there a way to get the behavior that exists in Word 2013? If that is not possible, then is there a way to open a document in the reading layout without messing up the user's view settings for future documents that they will open?

A little background: The Word Add-In that I am working on is used for creating document templates that can be used for generating documents from data in a database. The add-in has the ability to show a preview of a generated document from the current template. This preview should be opened in the reading layout since it is not intended to have changes made to it.

For reference, this is the whole function that contains the problem line of code:

public void OpenDocumentPreview(string path, bool showFeedback)
{
    _application.Documents.OpenNoRepairDialog(path, ReadOnly: true, AddToRecentFiles: false, Visible: true);
    _application.ActiveWindow.View.ReadingLayout = true;
    if (showFeedback)
    {
        _application.ActiveWindow.View.RevisionsFilter.Markup = WdRevisionsMarkup.wdRevisionsMarkupAll;
        _application.ActiveWindow.View.MarkupMode = WdRevisionsMode.wdBalloonRevisions;
        _application.ActiveWindow.View.ShowComments = true;
    }
}

Just in case you are wondering, I've tried some of the other Open methods (besides OpenNoRepairDialog). They all result in the same behavior.

1 Answer 1

1

This is probably not the most ideal solution, but it helped me solve a problem similar to yours. It involves having custom file extensions and using document events to check for them.

  • If other files are allowed to be opened before closing the preview file, you need to set ReadingLayout = false on the DocumentOpen event for them to open in Word's default editing mode.

  • If the preview file may be closed before another file is open, you need to do the same thing on the DocumentBeforeClose event.

This assumes you want all of your template files open in a print view mode for editing.

Setting Globals.YourAddin.Application.ActiveWindow.View.Type = WdViewType.wdPrintView may not be necessary, but without it my documents were opening in what looked to be a Web Layout view.

Globals.YourAddin.Application.DocumentOpen += doc =>
        {
            if (doc.Name.EndsWith(".customTemplateExtension"))
            {
                Globals.YourAddin.Application.ActiveWindow.View.ReadingLayout = false;
                Globals.YourAddin.Application.ActiveWindow.View.Type = WdViewType.wdPrintView;
            }
        };

Globals.YourAddin.Application.DocumentBeforeClose += (Document doc, ref bool cancel) =>
        {
            if (doc.Name.EndsWith(".customPreviewExtension"))
            {
                    Globals.YourAddin.Application.ActiveWindow.View.ReadingLayout = false;
            }
        };

Hopefully someone can provide a more elegant solution if there is one.

1
  • While this isn't an ideal solution, I've accepted the fact that Add-Ins for Word 2013 and Word 2016 just work differently, and that I may have to work around this by implementing something similar to your answer. Thanks. Jun 15, 2016 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.