0

I need Excel VBA to call another script language using shell. Ideally, also returning its output, but if that is hard to do, just to execute that other script and tell the user in a pop-up MessageBox where to get the output from and paste it into the Excel file.

I tried several ways, including (I took out some full file names):

pscmd = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -ExecutionPolicy Bypass -File ......\.....ps1"

or

Shell("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ""........ps1""", vbNormalFocus) - with full path to powershell or not

or

Shell("ruby.exe ""C:\testsoft\test.rb", "C:\testsoft\tst.txt""", vbNormalFocus)

or

Shell("powershell -ExecutionPolicy Bypass  "".....ps1 -input """ & pathVariable & """", 1)

or

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

but all to no avail.

It does not work at all with running a ruby script or powershell script or opening cmd.

For example, calling up some programs that I tested work though:

strCommand = "ping.exe 127.0.0.1" 
strCommand = "notepad.exe" ' works even with specifying a file to open  
strCommand = "calc.exe" 

My powershell or ruby scripts shall calculate MD5 checksums of PDFs created from Excel using VBA. They work on their own, just fine.

Is there an easy way?

BlueCoder
  • 1
  • 1
  • have you seen this answer ? https://stackoverflow.com/questions/11864765/call-ruby-script-from-powershell – Oliver Gaida Oct 23 '20 at 14:21
  • Hi, thank you for this hint. I have working scripts to calculate MD5 checksums, either in Ruby or Powershell, or Powershell calling Ruby and Ruby doing the MD5 calculation. My problem is that I want Excel VBA to call such script and either receive the output from Powershell/Ruby, or at least to let the user know where to find the MD5 checksum that the script calculated. My script can already output this into a text file. However, I am out of luck, neither Ruby nor Powershell I can call from VBA. – BlueCoder Oct 26 '20 at 07:40

0 Answers0