# Passing optional argument to win32 ole subsystem

**URL:** <https://www.ruby-forum.com/t/passing-optional-argument-to-win32-ole-subsystem/86418>\
**Category:** Ruby\
**Created:** [February 22, 2007, 3:31am UTC](https://www.ruby-forum.com/t/passing-optional-argument-to-win32-ole-subsystem/86418 "2007-02-22T03:31:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [February 22, 2007, 3:31am UTC](https://www.ruby-forum.com/t/passing-optional-argument-to-win32-ole-subsystem/86418/1 "2007-02-22T03:31:23Z")

</div>

Hi all,  
I am trying to embed a html document in Excel document using Win32OLE.  
The VBA Excel reference talks about this by using the OleObject Add  
method.  
However I am not sure how do I pass the optional argument in ruby which  
OLE  
will understand. Following is the snippet of the sample from VBA  
refernce.

# ============== |Set myDocument = Worksheets(1) myDocument.Shapes._AddOLEObject_ Left:=100, Top:=100, \_ Width:=200, Height:=300, \_ FileName:=“c:\my documents\testing.doc”, link:=True|

I tried passing null, but it failed miserably. I am not sure if I pass  
some argument incorrectly  
or the method I am using to pass the arguments is incorrect.  
Can somebody let me know the exact syntax in ruby to make this call  
successful.  
Any relevant pointers will be appreciated.

Thanks and Regards,  
Manish

---

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [February 22, 2007, 11:43am UTC](https://www.ruby-forum.com/t/passing-optional-argument-to-win32-ole-subsystem/86418/2 "2007-02-22T11:43:12Z")

</div>

On 2/22/07, Manish S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ==============  
> Manish  
> [Programming Ruby: The Pragmatic Programmer's Guide](http://ruby-doc.org/docs/ProgrammingRuby/html/win32.html#UB)

Named Arguments

Other automation client languages such as Visual Basic have the  
concept of named arguments. Suppose you had a Visual Basic routine  
with the signature:

Song(artist, title, length): rem Visual Basic

Instead of calling it with all three arguments in the order specified,  
you could use named arguments.

Song title := ‘Get It On’: rem Visual Basic

This is equivalent to the call Song(nil, ‘Get It On’, nil).

In Ruby, you can use this feature by passing a hash with the named  
arguments.

Song.new( ‘title’ =\> ‘Get It On’ )

* * *

So basically you just name those arguments you actually need:

myDocument.Shapes.AddOLEObject( ‘Left’ =\> 100, ‘Top’ =\> 100, ‘Width’ =\>  
200,  
‘Height’ =\> 300, ‘FileName’ =\> “c:\my documents\testing.doc”, ‘link’  
=\> true)
