Vbscript 如何打开已定义路径的文件

Vbscript 如何打开已定义路径的文件,vbscript,path,Vbscript,Path,到目前为止,代码仍然有效,但是当我尝试打开一个包含函数找到的路径的txt文件时,它不会打开txt文件。错误消息:对象不支持此属性或方法 Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") Function GetFilePath(FileName) Dim strScriptPath strScriptPath = objFSO.GetFile(WScript.ScriptFullName).ParentFolder

到目前为止,代码仍然有效,但是当我尝试打开一个包含函数找到的路径的txt文件时,它不会打开txt文件。错误消息:对象不支持此属性或方法

 Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

Function GetFilePath(FileName)
Dim strScriptPath
strScriptPath = objFSO.GetFile(WScript.ScriptFullName).ParentFolder.ParentFolder.ParentFolder.Path
GetFilePath = (strScriptPath & "\" & FileName & ".txt")
wscript.echo GetFilePath
End Function

GetFilePath("ApprovedShares")

'Reads Approvedshare txt and makes the txt file into an array
Dim objApprovedFile, StrApprovedPath
StrApprovedPath = ("" & GetFilePath("ApprovedShares") & "")
wscript.echo StrApprovedPath 
objApprovedFile = objFSO.OpenTextFile (StrApprovedPath)

您需要
Set
将对象分配给变量:

Set objApprovedFile = objFSO.OpenTextFile (StrApprovedPath)
仔细想想:

您需要更少()和更多“”:

==>


谢谢你的快速回复
StrApprovedPath = ("" & GetFilePath("ApprovedShares") & "")
StrApprovedPath = """" & GetFilePath("ApprovedShares") & """"