View Single Post
 
Old 04-10-2017, 01:07 PM
Thefirstfish` Thefirstfish` is offline Windows 10 Office 2016
Novice
 
Join Date: Dec 2015
Posts: 11
Thefirstfish` is on a distinguished road
Default Document Comparison

Edit: I figured out an answer to this question after a burst of inspiration.

My aim was to make a macro that duplicates a document, runs some editing macros on the new copy, then compares the original file with the new file. I'm doing it this way because having Track Changes on causes problems for the editing macros.

The working code is:

Code:
Sub Save_Then_Compare()

'Set original document as oDoc
Dim oDoc As Word.Document
Set oDoc = ActiveDocument

'Save original document
ActiveDocument.Save

'Select all text and paste into a new document
ActiveDocument.Range.Select
ActiveDocument.Range.Copy
Documents.Add
Selection.Paste

'Save as docx under a new filename
ActiveDocument.SaveAs2 Filename:="Output.docx", _
        FileFormat:=wdFormatDocumentDefault

'Run editing macros, then save and close the new file
EditMacro1
EditMacro2
ActiveDocument.Save
ActiveDocument.Close
        
'Compare the original and revised files and generate the comparison in oDoc
oDoc.Compare Name:="Output.docx", _
 CompareTarget:=wdCompareTargetCurrent, _
 IgnoreAllComparisonWarnings:=False, _
 Authorname:="Author"

Exit Sub
End Sub
Cheers,

Chris

Last edited by Thefirstfish`; 04-10-2017 at 05:52 PM. Reason: Found a solution
Reply With Quote