ruby screenshot?

A

aidy

Is there any way I an take a screenshot and paste it to Word through
Ruby. Here is hwat I have got.

require 'win32ole'

word = WIN32OLE.new('Word.Application')
#word.Visible = true
document = word.Documents.Open('c:\Screenshot.doc')
autoit = WIN32OLE.new("AutoItX3.Control")
autoit.Send"{PRINTSCREEN}"
...... what goes here
document.Close
word.Application.Quit

Cheers

Aidy
 
K

Kyle Schmitt

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


Good luck
--Kyle
 
D

Daniel Berger

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. =A0 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). =A0Dig up the docs for
scripting word from a more native microsoft scripting language.

<snip>

Save yourself some pain:

http://rubyforge.org/projects/win32screenshot/

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,588
Members
45,099
Latest member
AmbrosePri
Top