Announcement

Collapse
No announcement yet.

MS Word - use Word's own blackline compare

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MS Word - use Word's own blackline compare

    Is there any way to script BC to launch MS Word (365)'s own legal blackline compare instead of BC's own compare?

    That would save me a tremendous amount of time (Word's own compare looks at formatting and comments as well as just text).

    I think it ought to be possible because https://stackoverflow.com/questions/...command-prompt

  • #2
    Hello,

    For using Word to perform the conversion to Text then view within BC4, you can download the MS Word Extended format here:
    http://www.scootersoftware.com/downl..._moreformatsv4

    To launch a different viewer, you can define a BC4 External Format (Tools menu -> Format) and put in the appropriate command line argument to call another difftool. I'm not familiar if Word supports a call from the command line, but the included link above seems to use a wrapper script to perform that step. I don't think it's something Word officially supports, but if you can get it working from a regular command line (script file1 file2) then you can use the same command line launch from a BC4 External Format. The External Format also expects certain return codes, documented in the Help file, Settings Reference, File Formats, External Format:
    https://www.scootersoftware.com/v4he...algeneral.html
    Aaron P Scooter Software

    Comment


    • #3
      Originally posted by Aaron View Post
      Hello,
      To launch a different viewer, you can define a BC4 External Format (Tools menu -> Format) and put in the appropriate command line argument to call another difftool. I'm not familiar if Word supports a call from the command line, but the included link above seems to use a wrapper script to perform that step. I don't think it's something Word officially supports, but if you can get it working from a regular command line (script file1 file2) then you can use the same command line launch from a BC4 External Format. The External Format also expects certain return codes, documented in the Help file, Settings Reference, File Formats, External Format:
      https://www.scootersoftware.com/v4he...algeneral.html
      Thanks, that's what I'm trying to do. The real value BC supplies here is the user interface (just choose 2 files in Windows Explorer - vastly easier than doing it in Word).

      If I get it working, I'll let you know.

      Comment


      • #4
        I have it working!! This will save anybody who needs to compare legal documents in Word a load of time.

        Here's how to do it it, step-by-step:

        1 - Create a file called "Diff-Word.ps1" in the BC4 folder (usually "C:\Program Files\Beyond Compare 4")

        2 - Contents of that file should be:

        Code:
        param(
            [string] $BaseFileName,
            [string] $ChangedFileName
        )
        
        $ErrorActionPreference = 'Stop'
        
        function resolve($relativePath) {
            (Resolve-Path $relativePath).Path
        }
        
        $BaseFileName = resolve $BaseFileName
        $ChangedFileName = resolve $ChangedFileName
        
        # Remove the readonly attribute because Word is unable to compare readonly
        # files:
        $baseFile = Get-ChildItem $BaseFileName
        if ($baseFile.IsReadOnly) {
            $baseFile.IsReadOnly = $false
        }
        
        # Constants
        $wdDoNotSaveChanges = 0
        $wdCompareTargetNew = 2
        
        try {
            $word = New-Object -ComObject Word.Application
            $word.Visible = $true
            $old = $word.Documents.Open($BaseFileName, $false, $false)
            $old.Compare($ChangedFileName, [ref]"Comparison", [ref]$wdCompareTargetNew, [ref]$true, [ref]$true)
        
            $word.ActiveDocument.Saved = 1
        
            $new = $word.Documents.Open($ChangedFileName, $false, $false)
        
            # Now close the old document so only compare results window persists:
            $old.Close([ref]$wdDoNotSaveChanges)
        } catch {
            Add-Type -AssemblyName System.Windows.Forms
            [System.Windows.Forms.MessageBox]::Show($_.Exception)
        }
        (the above is modified from what I found at https://github.com/ForNeVeR/ExtDiff - many thanks to the author of that!!)

        3 - Open BC and do Tools>FileFormats, go to the bottom of the window that pops up and click '+', then choose "External Format".

        4 - In the Mask box paste in:
        Code:
        *.doc;*.docm;*.docx;*.dot;*.dotm;*.dotx
        5 - In the Quick Comparison and Compare View boxes paste in (both boxes should have identical content):
        Code:
        powershell -ExecutionPolicy ByPass -File Diff-Word.ps1 %1 %2
        6 - In Description paste in (if you care):
        Code:
        Make Word open it's own redline compare.
        7 - Click Save, click Close, exit BC.

        Now to use it, the order in which you do things matters (because of the way Word's redline compare works - it marks revisions against an "original"; if you do things in the wrong order you'll be marking the original against the revised verison, which isn't the same thing).

        So to use it:

        1 - Right click on the ORIGINAL file and choose "Select left file for compare".
        2 - Right click on the REVISED file and choose "Compare to".

        That's it. This will open 2 Word windows, one with the redline change marks (revised marked against original), and the other with the revised document (no changes - ready to edit further).

        If you don't want that 2nd window (just want the changes), put a '#' (comment) in front of the line that starts "$new =" in step 2 above.

        Note that if you start BC by selecting files and then right-click on "Compare", you must right click on the ORIGINAL file last (otherwise it'll compare in the wrong direction).

        If you don't like the order of selecting files and want to reverse it, just reverse the "%1 %2" to "%2 %1".

        Enjoy. Feel free to republish.

        Comment

        Working...
        X