标题: 新建一个word文档,然后打开之后,出现file in use, test.doc is locked for edit... [打印本页] 作者: carol_0921 时间: 2016-4-15 15:47 标题: 新建一个word文档,然后打开之后,出现file in use, test.doc is locked for edit... 我新建一个word文档,然后打开之后,出现file in use, test.doc is locked for edit...的一个对话框,为什么不能直接打开呢?
代码: Set oWordApp = CreateObject("Word.Application")
oWordApp.Visible=Ture Set oWordDoc = oWordApp.Documents.Add
oWordDoc.SaveAs "C:\Unified Functional Testing\Word\test.doc"
EditWordtext "C:\Unified Functional Testing\Word\test.doc","Step1: check input value is right"
Function EditWordtext (filepath,content) Set WordApp=CreateObject("Word.Application")
WordApp.Visible=True Set doc=WordApp.Documents.Open(filepath)
doc.content=content
doc.Save Set doc=Nothing Set WordApp=Nothing
ReadWord=True EndFunction
Set fso = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
Set WshShell = CreateObject("WScript.Shell")
oWord.displayAlerts=false
oWord.visible=False
If not (fso.FileExists(filepath)) Then
Set oWordDoc=oWord.Documents.Add
oWordDoc.SaveAs filepath
End If
Set oWordDoc=GetObject(filepath)
oWord.documents.open filepath,ForAppending,True
Set oDoc=oWord.ActiveDocument
Set oRange=oDoc.content
oRange.insertafter content
WshShell.SendKeys"{ENTER}"
wait(1)
oWord.ActiveDocument.Save
oWord.Application.Quit True
Set oRange=Nothing
Set oDoc=Nothing
Set oWord=Nothing