我需要在从我的 Windows 机器上的 VBA 宏中本地调用的 linux 服务器上远程运行命令(最终是脚本)。我在 Windows 命令提示符下测试了 VBA 之外的命令并且它可以工作,但我不确定如何从 VBA 宏中执行相同的操作,因为我需要传递参数值,这些值是组合框的选定值。我也无法将 Shell 的输出重定向到某个日志文件。我在网上查了几篇文章,得出了以下代码:
Private Sub UserForm_Initialize()
comboBox1.List = Array("A", "B", "C", "D")
comboBox2.List = Array("1", "2", "3", "4")
End Sub
Private Sub CommandButton1_Click()
Call runCommand
Unload Me
End Sub
Sub runCommand()
Dim Ret_Val
Dim Arg1 As String
Dim Arg2 As String
Dim command As String
Arg1 = comboBox1.Value
Arg2 = comboBox2.value
command = "C:\Program Files\PuTTY\plink.exe" & " -v" & " " & "user@host" & " -pw" & " " & "testpw" & " " & "echo &Arg1,&Arg2"
Ret_Val = Shell(command & ">C:\logs\log.txt", 1)
If Ret_Val = 0 Then
MsgBox "Error!", vbOKOnly
End If
End Sub
知道我在这里缺少什么吗?
你传递字符串“回声&ARG1,与Arg2所得”,而不是替代的价值Arg1
和Arg2
你需要更像:
command = "C:\Program Files\PuTTY\plink.exe -v user@host -pw testpw echo " & _
Arg1 & " " & Arg2
如果这不起作用,请提供您尝试生成的类型的已知工作命令行的示例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句