Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VBA/COM-methods with supplying options not possible #5758

Thomas008 opened this issue May 30, 2019 · 0 comments


None yet
2 participants
Copy link

commented May 30, 2019

excel ='Excel.Application')
workbooks = excel.Workbooks
workbook = workbooks.Open(File.expand_path('spec/data/workbook.xls'), 'ReadOnly' => true)

opening a workbook with readonly mode

Java::JavaLang::RuntimeException (createVariant() not implemented for class org.jruby.RubyHash

So it is not possible to provide a hash of options with the COM method.
One could avoid the problem via providing the options via their position.
In the above example, this would be
workbook = workbooks.Open(File.expand_path('spec/data/workbook.xls', nil, true)
(The first option parameter would be UpdateLinks that does not apply here. So it is set to nil).

However, for some COM methods, I don't see that you can provide the options via their position. for example, when adding or copying a worksheet into the workbook after a given worksheet.
In VBA you can proved either 'Before' or 'After', but not both these options.

a_worksheet = workbook.Worksheets.Item(1)
in ruby, you could do:
workbook.Worksheets.Add('Before' => a_worksheet)
In jruby this works fine:

In ruby:
workbook.Worksheets.Add('After' => a_worksheet)
I have not found a way to translate this to jruby. For example
workbook.Worksheets.Add(nil, a_worksheet)
then Excel raises an exception.

I have implemented a workaround by moving the worksheets in order to add or copy a worksheet (to the end), but it would be great, if one could provide a hash of options to the VBA methods.


jruby, windows 10

@headius headius added the windows label Jun 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.