【发布时间】:2016-11-02 00:53:26
【问题描述】:
我试图让 VBA 在服务器上创建一个文件夹。下面的代码工作正常:
Public pUser As String
Public pPass As String
Public pHost As String
Public cmd2 As Variant
Sub PlinkUserInfo()
Const cstrSftp1 As String = "C:\Program Files (x86)\PuTTY\plink.exe"
pUser = InputBox("Please enter your Putty username")
pPass = InputBox("Please enter your Putty password")
pHost = Workbooks("Robot Model.xlsm").Worksheets("Preparation").Range("C6").Value
pCommand = "cd /busbank/home; mkdir test3"
cmd2 = cstrSftp1 & " -l " & pUser & " -pw " & pPass & " -P 22 -2 -ssh " & pHost & " " & pCommand
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStlye As Integer: windowStyle = 1
Debug.Print cmd2
Call Shell(cmd2, vbNormalFocus)
End Sub
但是,我想把这段代码分成两部分,和另一个宏分开调用,如下:
Public pUser As String
Public pPass As String
Public pHost As String
Public cmd2 As Variant
Sub PlinkUserInfo()
Const cstrSftp1 As String = "C:\Program Files (x86)\PuTTY\plink.exe"
pUser = InputBox("Please enter your Putty username")
pPass = InputBox("Please enter your Putty password")
pHost = Workbooks("Robot Model.xlsm").Worksheets("Preparation").Range("C6").Value
End Sub
Sub PlinkRunCommand()
cmd2 = cstrSftp1 & " -l " & pUser & " -pw " & pPass & " -P 22 -2 -ssh " & pHost & " " & pCommand
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStlye As Integer: windowStyle = 1
Debug.Print cmd2
Call Shell(cmd2, vbNormalFocus)
End Sub
Public pCommand As Variant
Sub SetUpRemoteFolder()
Call PlinkUserInfo
pCommand = "cd /busbank/home; mkdir test3"
Call PlinkRunCommand
MsgBox ("The server folder is successfully created.")
End Sub
调用 Shell 部分给我运行时错误 5,无效的过程调用或参数。有谁知道为什么?
【问题讨论】:
-
你没有引用你的路径,所以它试图运行一个名为
c:\program的程序,参数为files (x86)\putty\plink.exe