Run ruby ​​script via vba

Is there a way to run a Ruby script from an Excel macro?

The macro creates two CSV files, and I would like to automate procss startup

ruby dostuff.rb file1.csv file2.csv
+4
source share
3 answers

The comments section made it clear: fully qualify your parameters if they are files and the files are not in the same directory as your Excel sheet.

Shell("ruby C:\Folder\dostuff.rb C:\Folder\file1.csv C:\Folder\file2.csv", vbNormalFocus)
+1
source

Sometimes you need to use the comspec environment variable to successfully run an external program from VBA. See blog search results for examples.

+1
source

ruby ​​ script VBA.

Shell, :

Public Sub RunRuby(file As String, ParamArray args())
  Shell "ruby.exe """ & file & """ " & Join(args, " ")
End Sub

Shell, :

Public Sub RunRuby(file As String, ParamArray args())
  Shell "rubyw.exe """ & file & """ " & Join(args, " ")
End Function

WScript.Shell, :

Public Function RunRuby(file As String, ParamArray args()) As Long
  Dim obj As Object
  Set obj = CreateObject("WScript.Shell")
  RunRuby = obj.Run("rubyw.exe """ & file & """ " & Join(args, " "), 0, True)
End Function

, :

ChDir "C:\Folder1"

or with the folder of the current book:

ChDir ThisWorkbook.Path
+1
source

Source: https://habr.com/ru/post/1620371/


All Articles