# Check for Open Application

**URL:** <https://www.ruby-forum.com/t/check-for-open-application/139196>\
**Category:** Ruby\
**Created:** [June 1, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/check-for-open-application/139196 "2008-06-01T17:06:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![koooee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b487fb/32.png) [@koooee](https://www.ruby-forum.com/u/koooee)\
**Post date:** [June 1, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/check-for-open-application/139196/1 "2008-06-01T17:06:41Z")

</div>

Hello,

I am trying to write a simple script and all I need to do is check if  
there is all ready a running instance of the word application. I look  
and couldn’t find much on google how to do this…which probably means  
it’s really easy, so I’m sorry for this post but I’m still learning 🙂

Thanks in advance for your help!

koooee

---

<div class="post-metadata">

**Author:** ![koooee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b487fb/32.png) [@koooee](https://www.ruby-forum.com/u/koooee)\
**Post date:** [June 1, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/check-for-open-application/139196/2 "2008-06-01T17:20:18Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Not T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> there is all ready a running instance of the word application. I look

Microsoft Word?

> and couldn’t find much on google how to do this…which probably means

Which OS?  
On the Mac you can use Apple Events or NSWorkspace through various  
bridges.

---

<div class="post-metadata">

**Author:** ![koooee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b487fb/32.png) [@koooee](https://www.ruby-forum.com/u/koooee)\
**Post date:** [June 1, 2008, 5:30pm UTC](https://www.ruby-forum.com/t/check-for-open-application/139196/3 "2008-06-01T17:30:44Z")

</div>

Tobias W. wrote:

> In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
> Not T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > there is all ready a running instance of the word application. I look
> 
> Microsoft Word?

Yes Microsfot Word

> > and couldn’t find much on google how to do this…which probably means
> 
> Which OS?  
> On the Mac you can use Apple Events or NSWorkspace through various  
> bridges.

Windows Vista is the OS.

Thanks for the interest!

koooee

---

<div class="post-metadata">

**Author:** ![koooee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b487fb/32.png) [@koooee](https://www.ruby-forum.com/u/koooee)\
**Post date:** [June 1, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/check-for-open-application/139196/4 "2008-06-01T18:14:43Z")

</div>

Not T. wrote:

> Hello,
> 
> I am trying to write a simple script and all I need to do is check if  
> there is all ready a running instance of the word application. I look  
> and couldn’t find much on google how to do this…which probably means  
> it’s really easy, so I’m sorry for this post but I’m still learning 🙂
> 
> Thanks in advance for your help!
> 
> koooee

One option is to try to connect to a running instance of Word. If there  
is no running instance of Word, a WIN32OLERuntimeError exception will be  
raised. So you could do the following:

require ‘win32ole’

begin  
word = WIN32OLE.connect(‘Word.Application’)  
rescue WIN32OLERuntimeError  
word = WIN32OLE.new(‘Word.Application’)  
word.Visible = true  
end

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

> **[Ruby on Windows](http://rubyonwindows.blogspot.com/search/label/word)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![koooee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b487fb/32.png) [@koooee](https://www.ruby-forum.com/u/koooee)\
**Post date:** [June 1, 2008, 7:26pm UTC](https://www.ruby-forum.com/t/check-for-open-application/139196/5 "2008-06-01T19:26:11Z")

</div>

David M. wrote:

> One option is to try to connect to a running instance of Word. If there  
> is no running instance of Word, a WIN32OLERuntimeError exception will be  
> raised. So you could do the following:
> 
> require ‘win32ole’
> 
> begin  
> word = WIN32OLE.connect(‘Word.Application’)  
> rescue WIN32OLERuntimeError  
> word = WIN32OLE.new(‘Word.Application’)  
> word.Visible = true  
> end
> 
> David
> 
> [http://rubyonwindows.blogspot.com](http://rubyonwindows.blogspot.com)  
> [Ruby on Windows: word](http://rubyonwindows.blogspot.com/search/label/word)

Awsome thank you so much!!
