question

FrantaDvojka-6984 avatar image
0 Votes"
FrantaDvojka-6984 asked FrantaDvojka-6984 edited

How to load original and revised docs to wdDialogToolsCompareDocuments built-in dialog

Hello,
Try as I may I cannot figure out how to load original and revised docs to wdDialogToolsCompareDocuments dialog built in MS Word:

C#
dynamic dialog = Application.Dialogs[Word.WdWordDialog.wdDialogToolsCompareDocuments]

May I ask for a hint?

Many thanks in advance,
Franta Dvojka

dotnet-csharp
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


It is probably possible to display the dialog, then to find and modify the child comboboxes (using Windows functions). But if you want just to compare two documents, then consider Application.CompareDocuments.


0 Votes 0 ·

If you invoke the Application.CompareDocuments method you will find out real quick that the wdDialogToolsCompareDocuments does not pop-up. Thus, the user cannot tune the built-in options for his job at runtime.



0 Votes 0 ·

To allow the users to customise the comparison, consider an obvious approach, which is based on Application.CompareDocuments.


0 Votes 0 ·
Show more comments

TimonYang,
on Aug 25, 2021 7AM GMT this webpage indicates you edited this thread 22 hrs ago. Try as I may I cannot discern your update. If I am not mistaken there is no Aug 24 or Aug 25 timestamp throughout this page.

No biggie. Just to let you know that the hierarchical structure of this thread got a tad out of my control.

0 Votes 0 ·

@FrantaDvojka-6984
Well, I wrote combobox as combox in the comments of the previous code. I saw this error yesterday and modified it.

0 Votes 0 ·
TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered TimonYang-MSFT edited

I'm afraid we can't do it. According to the document, the parameter list of wdDialogToolsCompareDocuments dialog has the following:

CompareDestination , DetectFormatting , IgnoreCompareWarn , UseFormatFrom , AddToMru , Merge , FilterPrivacy , FilterDateAndTime , Name , CompareAuthor

We cannot specify the origin and revised docs programmatically.

Update(8/10):
I tried to use UIAutomation to set its value, but after some tests, I came to the same conclusion as before that this combobox cannot be set programmatically.

If a combobox can accept input, like this:

121961-capture.png

Then we can set its value through UIAutomation:

         [DllImport("user32")]
         private static extern IntPtr GetForegroundWindow();
         static void Main(string[] args)
         {
             Thread.Sle*ep(2000);
             IntPtr intPtr = GetForegroundWindow();
             AutomationElement automationElement = AutomationElement.FromHandle(intPtr);
             var listBoxItems = automationElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "Edit"));
             ValuePattern value = listBoxItems[0].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
             value.SetValue(@"c:\test\1.docx");
         }

But the two comboxes in the wdDialogToolsCompareDocuments dialog box do not allow input and can only select items, so UIAutomation cannot affect them.

I can find this combobox with the following code, but nothing more.

     [DllImport("user32")]
     private static extern IntPtr GetForegroundWindow();
     static void Main(string[] args)
     {
         Microsoft.Office.Interop.Word.Application oWordApplication = new Microsoft.Office.Interop.Word.Application();
    
         System.Threading.Tasks.Task _task = System.Threading.Tasks.Task.Factory.StartNew(() => AutomationSequence());
         oWordApplication.Dialogs[WdWordDialog.wdDialogToolsCompareDocuments].Show();
         Console.WriteLine();
     }

     private static void AutomationSequence()
     {
         Thread.Slee*p(2000);
         IntPtr intPtr = GetForegroundWindow();
         AutomationElement automationElement = AutomationElement.FromHandle(intPtr);
         //There are two elements here, the combobox and the text above it, they have the same name
         var comBoxItems = automationElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Original document"));
            
         //ValuePattern value = comBoxItems[1].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
         //value.SetValue(@"c:\test\1.docx");
         Console.WriteLine();
     }

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


capture.png (1.2 KiB)
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

But the two comboxes in the wdDialogToolsCompareDocuments dialog box do not allow input and can only select items, so UIAutomation cannot affect them.

They must be expanded (ExpandCollapsePattern), like Inspect does to list the items, then they can be selected

1 Vote 1 ·

Thank you so very much for your efforts.

Do you think you could recommend a workaround?

In order to be fully compatible with future versions of MS Word my preferences is to use a MS Word built-in dialog for file comparison options rather than a local carbon copy/image.

0 Votes 0 ·

I hope this is only a documentation issue rather than missing functionality.

If you are convinced that original and revised files are not accessible in this dialog, can you recommend a workaround?

My task is to configure the two files in question /i.e. fill in the two drop-down lists/ and let the user optimize all the other comparison options available.

0 Votes 0 ·

@FrantaDvojka-6984
I wrote some code for testing, but unfortunately, my conclusion is still that we cannot modify it programmatically.
I revised my answer and added some content to explain why, please check it out.

1 Vote 1 ·

Thank you so very much for your detailed analysis.
Well, the outcome does not look auspiciously.

Do you think you could recommend a workaround?

In order to be fully compatible with future versions of MS Word my preferences is to use a MS Word built-in dialog for file comparison options rather than a local carbon copy/image.

0 Votes 0 ·
Show more comments
Castorix31 avatar image
0 Votes"
Castorix31 answered FrantaDvojka-6984 commented

This works for me :

 Microsoft.Office.Interop.Word.Application oWordApplication = new Microsoft.Office.Interop.Word.Application();
 oWordApplication.Visible = true;
 oWordApplication.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsCompareDocuments].Show();  
 //...        
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The show method shows the dialog.
How can I load origin and revised docs programmatically?

0 Votes 0 ·

If you want to fill the data in the DialogBox, it can be done with UIAutomation
(I tried first with Reflexion (InvokeMember, BindingFlags.SetProperty, ...) but failed (maybe it is possible too...))


0 Votes 0 ·

Yes, I want to fill in the data in the dialog box.
For that reason I need to know the names and signature for the public methods/properties designed for original and revised files.

I have noticed that you are an MVP. May I ask you to indicate where I can find relevant MS documentation?

0 Votes 0 ·