.bat launched Word 2003 will not close using Application.Quit

.bat launched Word 2003 will not close using Application.Quit

Post by yappat » Mon, 08 Nov 2004 04:13:05


Hi
I never normally use VBA/Word/Macro so this is probably quite simple,
but it's got me stumped - any help most appreciated!
I have been given a macro (pasted at the end of the message) which is
meant to save each active Word document as xml and then close it
(apart from the one it is in), then close the document with the macro
in it and then quit Word. I'm running this macro from the command
line, using two two .bat scripts
first script (doConvertToWordML.bat)
~~~~~~~~~
echo on
set LIST=
for %%i in (*.doc) do set LIST=!LIST! "%%i"

IF NOT EXIST "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
echo Couldn't find Word 2003 at: C:\Program Files\Microsoft
Office\OFFICE11\WINWORD.EXE

"C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" /msaveAsXML
%LIST% .\util\XMLmacro.doc
~~~~~~~~~

Second script:
~~~~~~~~~
cmd /v:on /c doConvertToWordML.bat
~~~~~~~~~
I don't know much about batch scripts either so I assume these are
correct.

Anyhow the problem is that it saves, closes all the documents but then
instead of exiting, Word creates a blank Document1.doc and remains
defiantly not closed on the screen. This means the system console is
blocked until I kill Word manually.
How can I make it die?

Cheers

Simon

(running win xp, word 2003)
saveAsXML macro:
~~~~~~~


Sub saveAsXML()
'
' saveAsXML Macro
' Macro recorded 27/10/2004
'
For i = 1 To Application.Documents.Count
If Application.Documents(i).Name <> "XMLmacro.doc" Then
Dim xmlFilename As String
xmlFilename = Application.Documents(i).Path & "\" &
Application.Documents(i).Name + ".xml"
With Application.Documents(i)
.SaveAs FileName:=xmlFilename, FileFormat:=wdFormatXML, _
LockComments:=False, Password:="", AddToRecentFiles:=False,
WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False
End With
End If
Next i
For j = Application.Documents.Count To 1 Step -1
Application.Documents(j).Close SaveChanges:=wdDoNotSaveChanges

Next j

ActiveDocument.ActiveWindow.Close
Application.Quit SaveChanges:=wdDoNotSaveChanges

End Sub
 
 
 

.bat launched Word 2003 will not close using Application.Quit

Post by Andr » Thu, 11 Nov 2004 20:44:44

what if the switch /n is added (in the first batch file)?
"C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" /msaveAsXML /n
......


Simon M wrote