编写WSF脚本读取CSV触发Object Required错误,请求排查解决
问题原因及解决方法
你的错误出在错误使用Set关键字给字符串变量赋值。
VBScript里,Set仅用于给对象类型的变量赋值(比如objFSO、objInFile这类对象实例),而strSourcePath、strSourceFile、strData都是普通字符串变量,不能用Set,直接赋值即可。
修正后的代码:
<job id="Test_Script"> <script language="VBScript"> Dim objFSO, strSourcePath, strSourceFile, objInFile, strData strSourcePath = "C:\test\ERACSV\" strSourceFile = "Payments.csv" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objInFile = objFSO.OpenTextFile(strSourcePath & strSourceFile, 1, False) strData = objInFile.ReadAll objInFile.Close WScript.Echo strData </script> </job>
关键修正点:
- 移除
strSourcePath、strSourceFile、strData前的Set关键字 - 保留
objFSO、objInFile前的Set(因为它们是对象变量)
内容的提问来源于stack exchange,提问作者Travis Heeter
相关产品推荐
相关产品推荐

