通过VBA调用powershell或ruby脚本,理想情况下将输出带到Excel或将用户指向输出路径
我需要Excel VBA调用另一种使用shell的脚本语言。理想情况下,也可以返回其输出,但如果这很难做到,只需执行另一个脚本,并在弹出消息框中告诉用户从何处获取输出并将其粘贴到Excel文件中即可 我尝试了几种方法,包括(我拿出了一些完整的文件名): 或通过VBA调用powershell或ruby脚本,理想情况下将输出带到Excel或将用户指向输出路径,excel,ruby,vba,powershell,pdf,Excel,Ruby,Vba,Powershell,Pdf,我需要Excel VBA调用另一种使用shell的脚本语言。理想情况下,也可以返回其输出,但如果这很难做到,只需执行另一个脚本,并在弹出消息框中告诉用户从何处获取输出并将其粘贴到Excel文件中即可 我尝试了几种方法,包括(我拿出了一些完整的文件名): 或 Shell(“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”“……ps1”“,vbNormalFocus)-是否具有到powershell的完整路径 或 或 或 但一切都无
Shell(“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”“……ps1”“,vbNormalFocus)
-是否具有到powershell的完整路径
或
或
或
但一切都无济于事
运行ruby脚本、powershell脚本或打开cmd时,它根本不起作用
例如,调用一些我测试过的程序:
strCommand = "ping.exe 127.0.0.1"
strCommand = "notepad.exe" ' works even with specifying a file to open
strCommand = "calc.exe"
我的powershell或ruby脚本应使用VBA计算从Excel创建的PDF的MD5校验和。他们自己工作,很好
有简单的方法吗?你看到这个答案了吗?嗨,谢谢你的提示。我有计算MD5校验和的工作脚本,可以在Ruby或Powershell中,也可以在Powershell中调用Ruby和Ruby进行MD5计算。我的问题是,我希望Excel VBA调用这样的脚本,或者从Powershell/Ruby接收输出,或者至少让用户知道在哪里可以找到脚本计算的MD5校验和。我的脚本已经可以将其输出到文本文件中。然而,我运气不好,Ruby和Powershell都不能从VBA调用。
Shell("ruby.exe ""C:\testsoft\test.rb", "C:\testsoft\tst.txt""", vbNormalFocus)
Shell("powershell -ExecutionPolicy Bypass "".....ps1 -input """ & pathVariable & """", 1)
Sub RunPowershellScript()
strCommand = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -ExecutionPolicy Bypass -File ""C:\testsoft\mdruby-nolog.ps1"""
Set wshShell = CreateObject("WScript.Shell")
Set WshShellExec = wshShell.Exec(strCommand)
strOutput = WshShellExec.StdOut.ReadAll
MsgBox strOutput
End Sub
strCommand = "ping.exe 127.0.0.1"
strCommand = "notepad.exe" ' works even with specifying a file to open
strCommand = "calc.exe"