1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VBA で Ruby を動かす

Posted at

はじめに

前回の記事で、会社支給のパソコンにRubyをインストールすることに成功しました。

VBA最強ではありますが、速度やネットワーク関連でRubyを呼び出したいところです。

ここでは、次の記事を参照しています。

VBAソース

VBA
Option Explicit

Public Sub puts_Ruby01()
    Dim suji1 As String
    Dim suji2 As String
    Dim rb_file As String
    
    suji1 = "3"
    suji2 = "5"
    
    Dim WSH
    Dim wExec
    Dim cmd_str As String

    Set WSH = CreateObject("WScript.Shell")

    rb_file = ThisWorkbook.Path & "\puts_hello.rb"
    cmd_str = "ruby " & rb_file & " " & suji1 & " " & suji2
    cmd_str = Replace(cmd_str, "\", "/")
    Set wExec = WSH.Exec("%ComSpec% /c " & cmd_str)

    Do While wExec.Status = 0
        DoEvents
    Loop

    Debug.Print Val(wExec.StdOut.ReadAll)  'CMDから結果を受け取る

    Set wExec = Nothing
    Set WSH = Nothing
End Sub

ここでは、イミディエイトウィンドウにDebug.Printしています。

Ruby側ソース

ruby
puts ARGV.map(&:to_i).sum

ARGVは配列です。

実行結果

20221011.png

まとめ

  • VBA と ruby の連携を行った
  • @O_LUPAN さん、ありがとう
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?