Is it possible to call and use MSWORD in command line mode?

M

MK

Hello all,

Actually I would like to use the "Compare and modify" function in Word and
Excel, but instead of opening the word application to complete the task, is
there anyone know how to do it in command line mode? like c:\..\MSWORD
c:\test1.doc c:\test2.doc "Compare and modify"
or I need to write a VB program to call the function in MS office?
Any comment, suggestion?
or any related document for reference?
Thanx so mush for your help

MK
 
H

Helmut Weber

Hi MK,

this has often been discussed,
and I haven't seen a simple solution.

I'd try to start word with a macro,
like winword /mMycompare.

Put the names of the files to be compared
in a txt-file. Have the macro read the txt-file,
do the comparison and so forth.
but instead of opening the word application to complete the task, is
there anyone know how to do it in command line mode?

Word would be started anyway.

If You are somewhat familiar to VB,
it's as easy as that.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

MK

Hello Helmut Weber,

Thanx for yout reply, actually I would like to do a integration with the
office compare and merge function(include excel, word, powerpoint...) with my
vb application, so that the client only need to select the documents from my
vb program, and my vb program will do the jobs and launch the result for the
client. But if it does not support command line with function call, do you
have any suggestion on how to automate the works?
like:
1) setup a templete for word with auto start macro
2) program the vb to copy the source file to the templete word file
3) use command line to launch the templet word
would it work this way?

Thanx

MK
 
H

Helmut Weber

Hi,
controlling Word from VB is much the same as controlling Word
form Excel or Controlling Excel from Word.
Can't say a word to merge in Excel or other Office-applications.

You need something like this here, tested from Excel,
having set a reference to the Word-Library!

Sub Test100()
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Dim Fil1 As String
Dim Fil2 As String
Dim Fil3 As String
Set oWrd = New Word.Application
Fil1 = "c:\test\test1.doc"
Fil2 = "c:\test\test2.doc"
Fil3 = "c:\test\test3.doc"
Set oDoc = oWrd.Documents.Add(Fil1)
oDoc.Merge Fil2, mergetarget:=wdMergeTargetNew
oWrd.Visible = True
End Sub

What kind of tool (dialog, listbox, textbox) or anything you use,
to get the filenames, doesn't matter.

When testing this code, note, that a new Word-Object is created.
In case you get an error, Winword.exe might still be in the
process-list.
With every error therefore, You get an additional Word-Object.
You may either kill the word-objects via the task-manager.
or use an already running instance of Word (getobject).

Anyway, can't be explained all here
and there remains some work to do for you.

Helmut Weber MVP WordVBA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top