# Win32ole and autofilling

**URL:** <https://www.ruby-forum.com/t/win32ole-and-autofilling/132038>\
**Category:** Ruby\
**Created:** [March 15, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/win32ole-and-autofilling/132038 "2008-03-15T19:46:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 15, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/win32ole-and-autofilling/132038/1 "2008-03-15T19:46:01Z")

</div>

Does anyone know how to perform an autofill within an Excel workbook  
via win32ole?

I’ve tried a couple of things that don’t work and I’m now stumped.

e.g.  
worksheet.Range(“F2”).AutoFill #=\> yields “parameter not optional”,  
so we’re on the right track, but obviously need to tell the worksheet  
_where_ to autofill

worksheet.Range(“F2”).AutoFill(“F3:F20”) # gives Unable to get the  
AutoFill property of the Range class

worksheet.Range(“F2”).AutoFill(“Destination” =\> “F3:F20”, “Type”=\>0) #  
gives Unable to get the AutoFill property of the Range class

worksheet.Range(“F2”).AutoFill(“Destination” =\> ‘Range(“F3:F20”)’,  
“Type” =\> 0) # gives Unable to get the AutoFill property of the Range  
class

worksheet.Range(“F2”).AutoFill(“Destination” =\> ‘Range(“F3:F20”)’,  
“Type”=\>“0”) # gives Unable to get the AutoFill property of the Range  
class

???

The VBA code for autofilling looks like this, but i’m not sure what  
syntax I should use for win32ole  
Range(“F2”).Select  
Selection.AutoFill Destination:=Range(“F3:F20”),  
Type:=xlFillDefault

TIA

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 15, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/win32ole-and-autofilling/132038/2 "2008-03-15T22:32:56Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Does anyone know how to perform an autofill within an Excel workbook  
> via win32ole?

(…)  
This more of a VBA question then a ruby problem.  
On my excel 2003:

require ‘win32ole’  
xcel = WIN32OLE.new(‘excel.application’)  
xcel.visible = true  
xcel.workbooks.add

xcel.range(“A1:B1”).value = 1

start1 = xcel.range(“A1”)  
start2 = xcel.range(“B1”)  
target1 = xcel.range(“A1:A10”)  
target2 = xcel.range(“B1:B10”)

start1.autofill(target1)  
start2.autofill(target2 , 2)  
#this can also be done by putting 2 in B2 and  
#setting start2 to range(B1:B2)

Regards,

Siep
