# VBA to Ruby code translate

**URL:** <https://www.ruby-forum.com/t/vba-to-ruby-code-translate/78178>\
**Category:** Ruby\
**Created:** [December 3, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/vba-to-ruby-code-translate/78178 "2006-12-03T17:57:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 3, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/vba-to-ruby-code-translate/78178/1 "2006-12-03T17:57:00Z")

</div>

Hi all,

I know I post this question a while ago in Ruby-forum  
but I haven’t figure out the solution yet. I hope  
someone from Ruby-talk can help me out to translate  
VBA code into ruby code.

Thanks,

Li

In my ruby script I include these on the top

require ‘win32ole’  
module Excel\_Const  
end

excel=WIN32OLE.new(‘Excel.Application’)  
WIN32OLE.const\_load(excel, Excel\_Const)  
…

I already create a worksheet object and a chart object  
and draw a graph. Also I translate all excel constants

into Excel\_Const::Xxx format  
Then I want to add some errorbars, which have the  
following VBA code :

ActiveSheet.Shapes(“Chart 1”).IncrementLeft -133.5  
ActiveSheet.Shapes(“Chart 1”).IncrementTop 9#  
ActiveChart.SeriesCollection(1).Select  
ActiveChart.SeriesCollection(1).ErrorBar  
Direction:=xlY, Include:=xlBoth, \_  
Type:=xlCustom, Amount:="=Sheet1!R5C2:R5C6",  
MinusValues:= \_  
“=Sheet1!R5C2:R5C6”  
ActiveChart.SeriesCollection(2).Select  
ActiveChart.SeriesCollection(2).ErrorBar  
Direction:=xlY, Include:=xlBoth, \_  
Type:=xlCustom, Amount:="=Sheet1!R6C2:R6C6",  
MinusValues:= \_  
“=Sheet1!R6C2:R6C6”

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 3, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/vba-to-ruby-code-translate/78178/2 "2006-12-03T21:54:46Z")

</div>

> ```
> ActiveChart.SeriesCollection(1).Select
> ActiveChart.SeriesCollection(1).ErrorBar
> Direction:=xlY, Include:=xlBoth, _
> Type:=xlCustom, Amount:="=Sheet1!R5C2:R5C6",
> MinusValues:= _
> "=Sheet1!R5C2:R5C6"
> 
> ```

Hi all,

I just figure out how to translate the above VBA code into Ruby code:  
changes some of them into a hash in Ruby

…  
activeChart.SeriesCollection(1).Select  
activeChart.SeriesCollection(1).ErrorBar(  
‘Direction’ =\> ExcelConst::XlY,  
‘Include’=\>ExcelConst::XlBoth,  
‘Type’=\>ExcelConst::XlCustom,  
‘Amount’=\>"=Sheet1!R5C2:R5C6",  
‘MinusValues’=\>"=Sheet1!R5C2:R5C6"  
)
