#include OleAutoObj objWordApplication = null OleAutoObj objDoc = null OleAutoObj objDocs = null OleAutoArgs objArgBlock = null /* Function: creatWordApplication() Purpose: creates the word application. Taken directly from word.dxl provided by DOORS */ void createWordApplication() { objArgBlock = create() // attaches to an existing word application objWordApplication = oleGetAutoObject(cObjWordApplication) if ( null objWordApplication ) { // creates a new word application objWordApplication = oleCreateAutoObject(cObjWordApplication) } } /* Function: openDocument(string) Purpose: opens a document having the given name and updates the objDoc global variable. Logs an error if the document could not be opened. Parameters: the full path to the document */ OleAutoObj openDocument(string docName) { olePut(objWordApplication, cPropertyVisible, true) oleGet(objWordApplication, cPropertyDocuments, objDoc) // open file clear(objArgBlock) put(objArgBlock, docName) oleMethod(objDoc, cMethodOpen, objArgBlock) if ( null == objDoc ) errorBox("Could not open the document named " docName) return objDoc } /* Function: toggleTrackRevision() Purpose: sets appropriate tracking settings */ void toggleTrackRevisions() { /************************WdColorIndex**********************/ //Override ole.inc colour not mapped correct for Word 2007 const int wdGreen = 12; olePut(objDoc, cPropertyTrackRevisions, true) OleAutoObj objOptions = null oleGet(objWordApplication, cPropertyOptions, objOptions) olePut(objOptions, cPropertyInsertedTextMark, wdInsertedTextMarkUnderline) olePut(objOptions, cPropertyInsertedTextColor, wdByAuthor) olePut(objOptions, cPropertyDeletedTextMark, wdDeletedTextMarkStrikeThrough) olePut(objOptions, cPropertyDeletedTextColor, wdByAuthor) olePut(objOptions, cPropertyRevisedPropertiesMark, wdRevisedPropertiesMarkNone) olePut(objOptions, cPropertyRevisedPropertiesColor, wdByAuthor) olePut(objOptions, cPropertyRevisedLinesMark, wdRevisedLinesMarkRightBorder) olePut(objOptions, cPropertyRevisedLinesColor, wdAuto) olePut(objOptions, cPropertyCommentsColor, wdByAuthor) olePut(objOptions, cPropertyRevisionsBalloonPrintOrientation, wdBalloonPrintOrientationPreserve) olePut(objOptions, cPropertyMoveFromTextMark, wdMoveFromTextMarkDoubleStrikeThrough) olePut(objOptions, cPropertyMoveFromTextColor, wdGreen) olePut(objOptions, cPropertyMoveToTextMark, wdMoveToTextMarkDoubleUnderline) olePut(objOptions, cPropertyMoveToTextColor, wdGreen) olePut(objOptions, cPropertyInsertedCellColor, wdCellColorLightBlue) olePut(objOptions, cPropertyMergedCellColor, wdCellColorLightYellow) olePut(objOptions, cPropertyDeletedCellColor, wdCellColorPink) olePut(objOptions, cPropertySplitCellColor, wdCellColorLightOrange) OleAutoObj objWindow = null OleAutoObj objView = null oleGet(objWordApplication, cPropertyActiveWindow, objWindow) oleGet(objWindow, cPropertyView, objView) olePut(objView, "RevisionsMode", wdMixedRevisions) OleAutoObj objADoc = null oleGet(objWordApplication, cPropertyActiveDocument, objADoc) olePut(objADoc, cPropertyTrackMoves, true) olePut(objADoc, cPropertyTrackFormatting, false) closeIfNonNull(objOptions) closeIfNonNull(objWindow) closeIfNonNull(objView) closeIfNonNull(objADoc) } /* Function: saveDocument(string) Purpose: saves the active document using the given document name. Parameters: the name of the document */ void saveDocument(string docName) { toggleTrackRevisions() clear(objArgBlock) put(objArgBlock, docName) put(objArgBlock, wdFormatXMLDocumentMacroEnabled) oleMethod(objDoc, cMethodSaveAs, objArgBlock) } /* Function: closeDocuments(void) Purpose: closes the active document using the given document name. Parameters: void */ void closeDocuments() { //Close all open files and shutdown Word OleAutoObj objApplication = null OleAutoObj objDocuments = null oleGet(objWordApplication, cPropertyApplication, objApplication) oleGet(objApplication, cPropertyDocuments, objDocuments) if ( null == objDocuments ) { errorBox("Could not retrieve the Documents collection from MS Word") return } //Loop Through open documents int count = 0 oleGet(objDocuments, cPropertyCount, count) while ( count != 0 ) { clear(objArgBlock) put(objArgBlock, 1) oleMethod(objDocuments, cMethodItem, objArgBlock, objDoc) oleMethod(objDoc, cMethodClose) oleGet(objDocuments, cPropertyCount, count) } //Quit Word no save oleMethod(objApplication, cMethodQuit) closeIfNonNull(objApplication) closeIfNonNull(objDocuments) } /* Function: createDocumentDiff(string, string) Purpose: Creates a diff file using the two existing documents having the given names. Creates a new document and makes it the active document. Parameters: The original document name, the revised document name. */ void createWordDiff(string original, string revised, string SaveAs) { createWordApplication() OleAutoObj objDocuments = null OleAutoObj objOriginalDoc = openDocument(original) OleAutoObj objRevisedDoc = openDocument(revised) oleGet(objWordApplication, cPropertyDocuments, objDocuments) if ( null == objDocuments ) { errorBox("Could not retrieve the Documents collection from MS Word") return } clear(objArgBlock) put(objArgBlock, original) oleMethod(objDocuments, cMethodItem, objArgBlock, objOriginalDoc) if ( null == objOriginalDoc ) { closeIfNonNull(objDocuments) errorBox("Could not retrieve the Original Document from the Documents Collection.") return } clear(objArgBlock) put(objArgBlock, revised) oleMethod(objDocuments, cMethodItem, objArgBlock, objRevisedDoc) if ( null == objRevisedDoc ) { closeIfNonNull(objDocuments) closeIfNonNull(objOriginalDoc) errorBox("Could not retrieve the Revised Document from the Documents Collection.") return } clear(objArgBlock); put(objArgBlock, objOriginalDoc) //originalDocument put(objArgBlock, objRevisedDoc) //revisedDocument put(objArgBlock, wdCompareDestinationNew) //Destination put(objArgBlock, wdGranularityWordLevel) //granularity put(objArgBlock, true) //compareFormatting put(objArgBlock, true) //compareCaseChanges put(objArgBlock, true) //compareWhitespace put(objArgBlock, true) //compareTables put(objArgBlock, true) //compareHeaders put(objArgBlock, true) //compareFootnotes put(objArgBlock, true) //compareTextboxes put(objArgBlock, true) //compareFields put(objArgBlock, true) //compareComments put(objArgBlock, true) //compareMoves oleMethod(objWordApplication, cMethodCompareDocuments, objArgBlock) oleGet(objWordApplication, cPropertyDocuments, objDocuments) clear(objArgBlock) put(objArgBlock, 1) oleMethod(objDocuments, cMethodItem, objArgBlock, objDoc) oleMethod(objDoc, cMethodActivate) saveDocument(SaveAs) closeDocuments() closeIfNonNull(objDocuments) closeIfNonNull(objOriginalDoc) closeIfNonNull(objRevisedDoc) } createWordDiff("P:\\Desktop\\jim.doc", "P:\\Desktop\\jim1.doc", "P:\\Desktop\\compare.docm") closeIfNonNull(objWordApplication) closeIfNonNull(objDoc) closeIfNonNull(objDocs) delete objArgBlock