# Automate Word OLE32 merge printing with Ruby

**URL:** <https://www.ruby-forum.com/t/automate-word-ole32-merge-printing-with-ruby/171244>\
**Category:** Ruby\
**Created:** [June 29, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/automate-word-ole32-merge-printing-with-ruby/171244 "2009-06-29T14:46:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 29, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/automate-word-ole32-merge-printing-with-ruby/171244/1 "2009-06-29T14:46:05Z")

</div>

What I would like to do is automate merge print documents without user  
interference.

I have come so far:

fso = WIN32OLE.new(“Scripting.FileSystemObject”)  
word = WIN32OLE.new(‘Word.Application’)  
path = fso.GetAbsolutePathName(ARGV.first)  
doc = word.Documents.Open(path)  
path = fso.GetAbsolutePathName(‘some.xls’)  
doc.MailMerge.OpenDataSource(path)

My questions:  
At the line:  
doc.MailMerge.OpenDataSource(path)  
Words asks for choosing table (which is actualy a worksheet in excel  
file). How can this be supresses or set automaticaly?

How to print all resulting documents?  
Recorded macro says:  
With ActiveDocument.MailMerge  
.Destination = wdSendToPrinter  
.SuppressBlankLines = True  
With .DataSource  
.FirstRecord = 1  
.LastRecord = 1  
End With  
.Execute Pause:=False  
end

by  
TheR
