A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Invoking compare and merge from the command line



 
 
Thread Tools Display Modes
  #1  
Old November 16th 07, 04:01 AM posted to microsoft.public.word.docmanagement
Wilhansen Li
external usenet poster
 
Posts: 1
Default Invoking compare and merge from the command line

I'm using Microsoft Word documents with a revision control system
(Mercurial). And I want MS Word to handle the merge and comparison when there
are conflicts. The only way for the tool to handle external programs is to
invoke them via command line (that means, no dde). Is there a way to invoke
Compare and Merge in word via command line switches? I can't see it in the
documentation.

If that doesn't really exist, I 'm thinking of two possible solutions:
1) Make a macro which does the invoking.
2) Make a program which invokes the compare and merge via COM.

Any suggestions on what I should do?
Ads
  #2  
Old November 16th 07, 02:50 PM posted to microsoft.public.word.docmanagement
Herb Tyson [MVP]
external usenet poster
 
Posts: 2,936
Default Invoking compare and merge from the command line

Your best bet might be to put the instructions into a macro, then invoke the
macro from the command line. For example:

"C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /mDoTheMerge

starts Word and runs a macro named "DoTheMerge". The command specified after
/m can be a macro or a built-in Word command.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com
"Wilhansen Li" Wilhansen wrote in message
...
I'm using Microsoft Word documents with a revision control system
(Mercurial). And I want MS Word to handle the merge and comparison when
there
are conflicts. The only way for the tool to handle external programs is to
invoke them via command line (that means, no dde). Is there a way to
invoke
Compare and Merge in word via command line switches? I can't see it in the
documentation.

If that doesn't really exist, I 'm thinking of two possible solutions:
1) Make a macro which does the invoking.
2) Make a program which invokes the compare and merge via COM.

Any suggestions on what I should do?


  #3  
Old November 16th 07, 04:10 PM posted to microsoft.public.word.docmanagement
Wilhansen Li[_2_]
external usenet poster
 
Posts: 3
Default Invoking compare and merge from the command line

But there's no way to pass (macro) parameters into the macros invoked that
way right?

"Herb Tyson [MVP]" wrote:

Your best bet might be to put the instructions into a macro, then invoke the
macro from the command line. For example:

"C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /mDoTheMerge

starts Word and runs a macro named "DoTheMerge". The command specified after
/m can be a macro or a built-in Word command.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com
"Wilhansen Li" Wilhansen wrote in message
...
I'm using Microsoft Word documents with a revision control system
(Mercurial). And I want MS Word to handle the merge and comparison when
there
are conflicts. The only way for the tool to handle external programs is to
invoke them via command line (that means, no dde). Is there a way to
invoke
Compare and Merge in word via command line switches? I can't see it in the
documentation.

If that doesn't really exist, I 'm thinking of two possible solutions:
1) Make a macro which does the invoking.
2) Make a program which invokes the compare and merge via COM.

Any suggestions on what I should do?



  #4  
Old November 16th 07, 04:47 PM posted to microsoft.public.word.docmanagement
Wilhansen Li[_2_]
external usenet poster
 
Posts: 3
Default Invoking compare and merge from the command line

I don't think there's really anyway so what I did was I opened both files and
invoked the compare operation like this:

Sub CompareAndMerge()
file1 = ActiveDocument.FullName
ActiveDocument.Close
file2 = ActiveDocument.FullName
ActiveDocument.Close
Documents.Open(file1).Merge (file2)
End Sub

So I just invoke it via command like like this:
WINWORD.exe mine.doc theirs.doc /mCompareAndMerge

Is this good enough? or are there better ways to do it?
  #5  
Old November 16th 07, 05:18 PM posted to microsoft.public.word.docmanagement
Jay Freedman
external usenet poster
 
Posts: 9,855
Default Invoking compare and merge from the command line

You could have your application write a text file to a known location, with
that file containing the full paths to the two files. Then the macro can
read the text file to get the file paths to use in the merge.

You are correct that there is no way to pass parameters directly on the
command line to a macro that's invoked with the /m switch.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Wilhansen Li wrote:
I don't think there's really anyway so what I did was I opened both
files and invoked the compare operation like this:

Sub CompareAndMerge()
file1 = ActiveDocument.FullName
ActiveDocument.Close
file2 = ActiveDocument.FullName
ActiveDocument.Close
Documents.Open(file1).Merge (file2)
End Sub

So I just invoke it via command like like this:
WINWORD.exe mine.doc theirs.doc /mCompareAndMerge

Is this good enough? or are there better ways to do it?



  #6  
Old November 17th 07, 04:19 AM posted to microsoft.public.word.docmanagement
Wilhansen Li[_2_]
external usenet poster
 
Posts: 3
Default Invoking compare and merge from the command line

Additionally, I also found a merge/diff script using the Windows Scripting
Host he

http://tortoisesvn.tigris.org/source...ts/diff-doc.js

http://tortoisesvn.tigris.org/source...s/merge-doc.js

Which calls Word via COM as I suspected.

Below is a copy-paste of diff-doc.js just as a reference:
var objArgs,num,sBaseDoc,sNewDoc,objScript,word,destin ation;
// Microsoft Office versions for Microsoft Windows OS
var vOffice2000 = 9;
var vOffice2002 = 10;
var vOffice2003 = 11;
var vOffice2007 = 12;
// WdCompareTarget
var wdCompareTargetSelected = 0;
var wdCompareTargetCurrent = 1;
var wdCompareTargetNew = 2;
// WdViewType
var wdMasterView = 5;
var wdNormalView = 1;
var wdOutlineView = 2;
// WdSaveOptions
var wdDoNotSaveChanges = 0;
var wdPromptToSaveChanges = -2;
var wdSaveChanges = -1;

objArgs = WScript.Arguments;
num = objArgs.length;
if (num 2)
{
WScript.Echo("Usage: [CScript | WScript] diff-doc.js base.doc new.doc");
WScript.Quit(1);
}

sBaseDoc = objArgs(0);
sNewDoc = objArgs(1);

objScript = new ActiveXObject("Scripting.FileSystemObject");
if ( ! objScript.FileExists(sBaseDoc))
{
WScript.Echo("File " + sBaseDoc + " does not exist. Cannot compare the
documents.");
WScript.Quit(1);
}
if ( ! objScript.FileExists(sNewDoc))
{
WScript.Echo("File " + sNewDoc + " does not exist. Cannot compare the
documents.");
WScript.Quit(1);
}

try
{
word = WScript.CreateObject("Word.Application");
}
catch(e)
{
// before giving up, try with OpenOffice
try
{
var OO;
OO = WScript.CreateObject("com.sun.star.ServiceManager" );
}
catch(e)
{
WScript.Echo("You must have Microsoft Word or OpenOffice installed to
perform this operation.");
WScript.Quit(1);
}
// yes, OO is installed - do the diff with that one instead
var objFile = objScript.GetFile(sNewDoc);
if ((objFile.Attributes & 1)==1)
{
// reset the readonly attribute
objFile.Attributes = objFile.Attributes & (~1);
}
//Create the DesktopSet
var objDesktop = OO.createInstance("com.sun.star.frame.Desktop");
var objUriTranslator =
OO.createInstance("com.sun.star.uri.ExternalUriRef erenceTranslator");
//Adjust the paths for OO
sBaseDoc = sBaseDoc.replace(/\\/g, "/");
sBaseDoc = sBaseDoc.replace(/:/g, "|");
sBaseDoc = sBaseDoc.replace(/ /g, "%20");
sBaseDoc="file:///" + sBaseDoc;
sBaseDoc=objUriTranslator.translateToInternal(sBas eDoc);
sNewDoc = sNewDoc.replace(/\\/g, "/");
sNewDoc = sNewDoc.replace(/:/g, "|");
sNewDoc = sNewDoc.replace(/ /g, "%20");
sNewDoc="file:///" + sNewDoc;
sNewDoc=objUriTranslator.translateToInternal(sNewD oc);

//Open the %base document
var oPropertyValue = new Array();
oPropertyValue[0] = OO.Bridge_GetStruct("com.sun.star.beans.PropertyVa lue");
oPropertyValue[0].Name = "ShowTrackedChanges";
oPropertyValue[0].Value = true;
var objDocument=objDesktop.loadComponentFromURL(sNewDo c,"_blank", 0,
oPropertyValue);

//Set the frame
var Frame = objDesktop.getCurrentFrame();

var dispatcher=OO.CreateInstance("com.sun.star.frame.D ispatchHelper");

//Execute the comparison
dispatcher.executeDispatch(Frame, ".uno:ShowTrackedChanges", "", 0,
oPropertyValue);
oPropertyValue[0].Name = "URL";
oPropertyValue[0].Value = sBaseDoc;
dispatcher.executeDispatch(Frame, ".uno:CompareDocuments", "", 0,
oPropertyValue);
WScript.Quit(0);
}

objScript = null;

word.visible = true;

// Open the new document
destination = word.Documents.Open(sNewDoc);

// If the Type property returns either wdOutlineView or wdMasterView and the
Count property returns zero, the current document is an outline.
if (((destination.ActiveWindow.View.Type == wdOutlineView) ||
(destination.ActiveWindow.View.Type == wdMasterView)) &&
(destination.Subdocuments.Count == 0))
{
// Change the Type property of the current document to normal
destination.ActiveWindow.View.Type = wdNormalView;
}

// Compare to the base document
if (Number(word.Version) = vOffice2000)
{
// Compare for Office 2000 and earlier
destination.Compare(sBaseDoc);
}
else
{
// Compare for Office XP (2002) and later
destination.Compare(sBaseDoc, "Comparison", wdCompareTargetNew, true,
true);
}

// Show the comparison result
if (Number(word.Version) vOffice2007)
{
word.ActiveDocument.Windows(1).Visible = 1;
}

// Mark the comparison document as saved to prevent the annoying
// "Save as" dialog from appearing.
word.ActiveDocument.Saved = 1;

// Close the first document
if (Number(word.Version) = vOffice2002)
{
destination.Close(wdDoNotSaveChanges);
}

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare and Merge IamWhoIam Microsoft Word Help 1 September 15th 07 06:24 AM
Compare and Merge – Legal Black Line - Word XP Mary Ann Microsoft Word Help 2 April 24th 07 12:16 PM
How do I select a vert block (alt-drag) without invoking research DaleZ New Users 1 November 17th 06 11:53 PM
Compare and Merge summary Hugh Murfitt Microsoft Word Help 2 January 26th 06 05:16 PM
merge and compare cntrymuscfan Microsoft Word Help 0 August 8th 05 05:59 PM


All times are GMT +1. The time now is 02:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright 2004-2020 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.