# Ruby screenshot?

**URL:** <https://www.ruby-forum.com/t/ruby-screenshot/130360>\
**Category:** Ruby\
**Created:** [February 27, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/ruby-screenshot/130360 "2008-02-27T17:01:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [February 27, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/ruby-screenshot/130360/1 "2008-02-27T17:01:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [February 27, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/ruby-screenshot/130360/2 "2008-02-27T22:13:28Z")

</div>

On Feb 27, 11:53 am, “Kyle S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

Save yourself some pain:

[http://rubyforge.org/projects/win32screenshot/](http://rubyforge.org/projects/win32screenshot/)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [February 27, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/ruby-screenshot/130360/3 "2008-02-27T17:54:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [February 27, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/ruby-screenshot/130360/4 "2008-02-27T22:57:03Z")

</div>

On Wed, Feb 27, 2008 at 3:12 PM, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Save yourself some pain:
> 
> [http://rubyforge.org/projects/win32screenshot/](http://rubyforge.org/projects/win32screenshot/)
> 
> Regards,
> 
> Dan

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
