It’s been so long since I’ve done this, I realized I forgot, and it
got to me, so I just played with it for a few minutes to refresh my
memory. It helps if you’ve had the unfortunate experience of having
scripted word before using {vb|j}script.
Sadly the ruby docs and webpages, as helpful as they are, don’t give
you a good feeling for the word ole object(s). Dig up the docs for
scripting word from a more native microsoft scripting language.
It’s been so long since I’ve done this, I realized I forgot, and it
got to me, so I just played with it for a few minutes to refresh my
memory. It helps if you’ve had the unfortunate experience of having
scripted word before using {vb|j}script.
Sadly the ruby docs and webpages, as helpful as they are, don’t give
you a good feeling for the word ole object(s). Dig up the docs for
scripting word from a more native microsoft scripting language.
require ‘irb/completion’ #unfortunately this doesn’t add completion for ole methods, but hey,
it’s nice to have…
require ‘win32ole’
word=WIN32OLE.new(‘Word.Application’) #Very important, so you can see what you’re doing #if you forget to do this, and ruby seems stuck/hung, #word is probably displaying some sort of dialog (like save) #and needs input. If that happens, open up another cmd #and run… #ruby -e “require
‘win32ole’;WIN32OLE.connect(‘Word.Application’).visible=true”
word.visible=true
word.Documents.Add()
word.Selection.Paste
word.ActiveDocument.SaveAs(‘C:\Test.doc’)
word.ActiveDocument.close
word.Quit
Hey, not a bad little lib.
Still, I don’t know if it would have solved his issue.
Apparently the ruby-win32ole bridge in 1.9 is better, so maybe it’ll
be less nightmareish to explore OLE in. Today was the first time I
used ruby in windows for maybe 4 months.
I like that.
–Kyle
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.