Search code examples
rubyexcelwin32olevba

Unexpected behavior using the run method for win32ole excel object


I have the following bit of ruby code which works fine

require 'WIN32OLE'
excel = WIN32OLE.new('Excel.Application')
excel.visible = true
path =  Dir.pwd + '\Testargs.xlsm'
excel.workbooks.open(path)
excel.run('IdontTakeargs')

Where IdontTakeargs is a macro in the Testargs.xlsm workbook.

If I attempt to call a macro which takes arguments ie:

excel.run('Itakeargs(1)')

This code also runs, but for some reason it runs the macro twice. The above snytax is somewhat of a guess as I can't locate an example of calling a macro with arguments.

Any help with what the correct syntax might be or even if what I am attempting to accomplish is even possible (call a macro that accepts arguments from ruby.)


Solution

  • The syntax to pass an argument to a VBA macro seems to be

    excel.run('Itakeargs', '1')
    

    Still, the observed (and reproducable) behaviour is somewhat strange.