MS Word API:在批处理模式下将.doc word文档保存为.docx

时间:2015-02-26 14:57:29

标签: vbscript ms-word save-as

我正在尝试打开doc文件并以批处理模式将其另存为docx。但即使visible属性设置为false,MSWord也会显示出来。

我的代码有问题吗?

If Wscript.Arguments.Count <> 2 Then
 Wscript.Echo "Wrong Arguments. Need 2 arguments; Filename and Output Directory."
 Wscript.quit
End If

Dim objApp
Dim objDoc
Dim objFile

fileName = Wscript.Arguments(0)
outputDirectory = Wscript.Arguments(1)

Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set MyObject = GetObject(fileName) 
if MyObject is Nothing then 
    objApp = CreateObject("Word.Application")
Else
    Set objApp = MyObject.Application
End If
objApp.Visible = False
Set objFile = objFSO.GetFile(fileName)
Set objDoc = objApp.Documents.Open(fileName)
objDoc.SaveAs objFSO.BuildPath( outputDirectory, objFSO.GetBaseName( objFile ) & ".docx" ), 12
objDoc.Close
objApp.Quit
Set objDoc = Nothing
Set objApp = Nothing

0 个答案:

没有答案