Vbscript 如何使用VBS保存InfoPath文档?
我无法通过VBScript在InfoPath中执行保存和关闭操作 我正在尝试执行一些简单的操作,以便稍后引入更改。我已经检查了我的语法是否正确……看起来是……但是脚本在保存和关闭操作期间崩溃了 有没有VBS大师可以告诉我我做错了什么 这里的逻辑非常基本。 1.提供供我使用的InfoPath文件列表。 2.逐行循环浏览文件,并执行打开/保存/关闭操作。 3.退出程序 代码如下:Vbscript 如何使用VBS保存InfoPath文档?,vbscript,infopath,Vbscript,Infopath,我无法通过VBScript在InfoPath中执行保存和关闭操作 我正在尝试执行一些简单的操作,以便稍后引入更改。我已经检查了我的语法是否正确……看起来是……但是脚本在保存和关闭操作期间崩溃了 有没有VBS大师可以告诉我我做错了什么 这里的逻辑非常基本。 1.提供供我使用的InfoPath文件列表。 2.逐行循环浏览文件,并执行打开/保存/关闭操作。 3.退出程序 代码如下: 'This line gets the current working directory, based off str
'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()
编辑:将接受的答案合并到脚本中是对象的集合。它没有Save
方法,Close
方法的参数是要关闭的对象的索引,而不是布尔值。如果要保存并关闭特定对象,可能必须按如下方式执行:
Set xdoc = InfoPathObject.XDocuments.Open(fileName)
xdoc.Save
xdoc.CloseDocument
但未经测试,因为我手头没有足够的MS Office。感谢您回答@Ansgar。您对代码非常熟悉,我用它玩了大约30分钟,最后发现需要一些额外的引号与fileName参数相关。我不知道为什么,但你需要这些额外的报价。下面是更正的部分:
Set xdoc=InfoPathObject.XDocuments.Open(fileName+“”)xdoc.Save xdoc.CloseDocument