简体   繁体   中英

Enable built-in Microsoft Word button controls with Microsoft.Office.Interop.Word

I am currently in the need to compare two Microsoft Word documents with Microsoft.Office.Interop.Word . I've found the Application.CompareDocument method, which does exactly what I want. The following C# source code (snippet) compares a document saved in the filesystem with the current active document and opens the result in a new document:

using Word = Microsoft.Office.Interop.Word;

// [...]

Word.Document originalDocument = this.application.Documents.Open(filePath, ReadOnly: true, Visible: false);
Word.Document diffDocument = this.application.CompareDocuments(
    originalDocument,
    this.application.ActiveDocument);
((Word._Document)originalDocument).Close(SaveChanges: false);

// TODO Activate two built-in Microsoft Word buttons.

// [...]

But I also need to activate two built-in buttons in the view of the newly created Word document. After searching on MSDN for a while, I am unable to find a way to achieve what I want. I've added two screenshots to this question, which display the built-in buttons I want to activate (sadly, I am using the German version of Microsoft Word 2010, so I don't know what the exact translations are).

  1. "Quelldokumente anzeigen" (could be translated as "Display source documents"). I need to activate the button "Beide anzeigen" (could be translated as "Display both"). 按钮Quelldokumente anzeigen的屏幕截图

  2. "Überarbeitungsbereich" (could be translated as "Revision pane"). I need to activate the button "Überarbeitungsbereich vertikal..." (could be translated as "Vertical revision pane..."). 按钮Überarbeitungsbereich的屏幕截图

To conclude, I want to know how I can modifiy the state (either directly or indirectly via an method call) of these two buttons.

EDIT (2013-08-03)

The revisions pane can be set via the following method:

diffDocument.ActiveWindow.View.SplitSpecial = Word.WdSpecialPane.wdPaneRevisionsVert;

I am still searching for a solution to display both the source document and revised document panes.

EDIT (2013-08-05)

The show source documents button can be modified to show both source documents via the following method:

diffDocument.ActiveWindow.ShowSourceDocuments = Word.WdShowSourceDocuments.wdShowSourceDocumentsBoth;

Possible solutions of your problems:

Ad 1. but first, you need to open your documents with ReadOnly: false while,according to both C# and VBA test it will not work when you set parameters to ReadOnly: true :

((Word._Document)diffDocument).Windows.CompareSideBySideWith(originalDocument);

Ad 2. this time you need to refer to window object of Word Application. Here is code for active window:

appWRD.ActiveWindow.View.SplitSpecial = Word.WdSpecialPane.wdPaneRevisionsVert;

where: appWRD is Word.Application in my code.

Ad 1 again. (one above was a result of misunderstanding).

According to some test this code should give you what you need:

appWRD.ActiveWindow.ShowSourceDocuments = Word.WdShowSourceDocuments.wdShowSourceDocumentsBoth;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM