Vbscript 无法在.vbs文件中获取当前目录

Vbscript 无法在.vbs文件中获取当前目录,vbscript,Vbscript,我编写了一个Visual Basic脚本来执行Excel宏。我想动态设置.xlsm文件的位置。我使用FileSystemObject获取当前目录。它返回C:\Windows\System32,但我需要.vbs文件所在的目录 我尝试使用FileSystemObject和WScript获取当前目录,但没有成功 ' Create a FileSystemObject to get the current directory Dim fso Set fso = CreateObject("Scripti

我编写了一个Visual Basic脚本来执行Excel宏。我想动态设置.xlsm文件的位置。我使用FileSystemObject获取当前目录。它返回C:\Windows\System32,但我需要.vbs文件所在的目录

我尝试使用FileSystemObject和WScript获取当前目录,但没有成功

' Create a FileSystemObject to get the current directory
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
strPath = fso.GetAbsolutePathName(".")
myExcelWorker.DefaultFilePath = strPath

' Open the Workbook specified on the command-line 
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = strPath & "\Data center Wattsight long term.xlsm"

Set oWorkBook = myExcelWorker.Workbooks.Open(strWorkerWB)
预期的行为是打开Excel文件。但我有一个错误:

您将当前工作目录与脚本的位置混淆。这两者并不相同

以下任一项将为您提供当前工作目录:

CreateObject(“WScript.Shell”).CurrentDirectory
CreateObject(“Scripting.FileSystemObject”).GetAbsolutePathName(“.”)
这将为您提供脚本的位置:

CreateObject(“Scripting.FileSystemObject”).GetParentFolderName(WScript.ScriptFullName)
您将当前工作目录与脚本的位置混淆了。这两者并不相同

以下任一项将为您提供当前工作目录:

CreateObject(“WScript.Shell”).CurrentDirectory
CreateObject(“Scripting.FileSystemObject”).GetAbsolutePathName(“.”)
这将为您提供脚本的位置:

CreateObject(“Scripting.FileSystemObject”).GetParentFolderName(WScript.ScriptFullName)