VBA 在命令行中调用变量
Calling a Variable on the Command Line in VBA
我的 VBA 脚本中有一个变量,我试图在脚本中的命令行中调用该变量。
Sub Test()
'Set enviro to %APPDATA%
Dim enviro As String
enviro = CStr(Environ("APPDATA"))
'Create a new variable that sets the file path for the RepoDir.txt
RepoPath = enviro & "\RepoDir.txt"
'Create a new variable to grab the line of text in RepoDir.txt
Dim FilePath As String
Dim strFirstLine As String
'The new variable calls the RepoPath Variable
FilePath = RepoPath
Open FilePath For Input As #1
Line Input #1, strFirstLine
'MsgBox (strFirstLine)
Shell ("cmd /c cd call strFirstLine & git pull RandomSig > %TEMP%\gitPull.txt 2>&1")
End Sub
我正在尝试调用变量 strFirstLine,它包含我希望命令行读取然后 CD 到它的路径。有办法吗?
谢谢!
您需要传递 strFirsLine 的 值,而不是名称。使用(示例):
Shell ("cmd /c cd " & strFirstLine & "git ..."
我的 VBA 脚本中有一个变量,我试图在脚本中的命令行中调用该变量。
Sub Test()
'Set enviro to %APPDATA%
Dim enviro As String
enviro = CStr(Environ("APPDATA"))
'Create a new variable that sets the file path for the RepoDir.txt
RepoPath = enviro & "\RepoDir.txt"
'Create a new variable to grab the line of text in RepoDir.txt
Dim FilePath As String
Dim strFirstLine As String
'The new variable calls the RepoPath Variable
FilePath = RepoPath
Open FilePath For Input As #1
Line Input #1, strFirstLine
'MsgBox (strFirstLine)
Shell ("cmd /c cd call strFirstLine & git pull RandomSig > %TEMP%\gitPull.txt 2>&1")
End Sub
我正在尝试调用变量 strFirstLine,它包含我希望命令行读取然后 CD 到它的路径。有办法吗?
谢谢!
您需要传递 strFirsLine 的 值,而不是名称。使用(示例):
Shell ("cmd /c cd " & strFirstLine & "git ..."