I use this to open a "template" (really just a plain Word document with [text to replace] inside), do the substitutions, and save as a new filename.
1
2 require 'win32ole'
3
4 word = WIN32OLE.new('Word.Application')
5
6 doc = word.Documents.Open('c:\file_to_open.doc')
7 {
8 'name' => 'Tim Morgan',
9 'date' => Date.today.strftime('%B %d, %Y'),
10 ...
11 }.each do |key, value|
12 word.Selection.HomeKey(unit=6)
13 find = word.Selection.Find
14 find.Text = "[#{key}]"
15 while word.Selection.Find.Execute
16 word.Selection.TypeText(text=value)
17 end
18 end
19 doc.SaveAs('c:\output_file.doc')
20 doc.Close