我在通过 VBScript 在 InfoPath 中执行保存和关闭操作时遇到了困难。
我试图只执行一些简单的操作,所以我可以稍后介绍更改。我检查了MSDN以确保我的语法是正确的......而且似乎......但是脚本在 SAVE 和 CLOSE 操作期间崩溃了。
有没有 VBS 大师可以告诉我我做错了什么?
这里的逻辑非常基本。1. 提供 InfoPath 文件列表供我使用。2. 逐行循环文件,执行打开/保存/关闭操作。3. 退出程序。
这是代码:
'This line gets the current working directory, based off string subtraction from the absolute path of the script - the script's name
workingDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(Len(WScript.ScriptName)))
'We need to provide a name for the file we're going to read. It's nice to keep this in one place, and not let it change.
Const XMLList = "XML Targets.txt"
'Create a file system object so we can open the list of XML files that you want opened
Set fso = CreateObject("Scripting.FileSystemObject")
'General Error checking, Just making sure there's a XML List file to read from.
If fso.FileExists(workingDirectory & XMLList) Then
Set targetFile = fso.OpenTextFile(workingDirectory & XMLList)
Else
MsgBox "You need to have a file called '" & XMLList & "' in the same directory as the script!", 16, "Error"
WScript.quit()
End If
'Assuming you get this far, you loop through the list file line by line and open/save/close the documents
Do While Not targetFile.AtEndOfStream
'Create an InfoPath Application object so we can manipulate our files in InfoPath
Set InfoPathObject = CreateObject("InfoPath.Application")
fileName = targetFile.ReadLine()
Set xdoc = InfoPathObject.XDocuments.Open(fileName+"") 'Open the file (Suggested by Ansgar)
xdoc.Save 'Save the file (Suggested by Ansgar)
xdoc.CloseDocument 'Close the file (Suggested by Ansgar)
Loop
MsgBox "Done"
WScript.quit()
编辑:将接受的答案合并到脚本中