473,799 Members | 3,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining if MS Word is running through VB code

Hi, I have an application that will run a method depending on whether
or not there is an instance of MS Word currently open.

How do I determine whether or not an executable from another program is
running? I am new to VB, but I suspect that this should definitely be
5 lines or less.

Sep 11 '06 #1
4 3414

njuneardave wrote:
Hi, I have an application that will run a method depending on whether
or not there is an instance of MS Word currently open.

How do I determine whether or not an executable from another program is
running? I am new to VB, but I suspect that this should definitely be
5 lines or less.
Well... One way with VB.NET would be to use the GetObject method.
Word is an automation server - and if it's running GetObject will
return a valid reference to it. If word isn't running then GetObject
will throw an exception. So, you can actually do this in one line of
code:

Dim wordObject As Object = GetObject (Class:="Word.A pplication")

--
Tom Shelton

Sep 11 '06 #2
Cool, Tom. Thanks!!

I guess I should have used a little less abstraction in this case,
though. Using MS Word was a prelim test. I actually want to test for
the existence of an executable that I made myself called,
"Spectrum.e xe". I first opened the application using:

System.Diagnost ics.Process.Sta rt("Spectrum.ex e")
Now, later in the code, I need to test if my Spectrum.exe is currently
running. Sorry about the abstraction.... I didn't think that it would
play a major role =P Anyway, any new tips?
Thanks so much for the help!

Tom Shelton wrote:
njuneardave wrote:
Hi, I have an application that will run a method depending on whether
or not there is an instance of MS Word currently open.

How do I determine whether or not an executable from another program is
running? I am new to VB, but I suspect that this should definitely be
5 lines or less.

Well... One way with VB.NET would be to use the GetObject method.
Word is an automation server - and if it's running GetObject will
return a valid reference to it. If word isn't running then GetObject
will throw an exception. So, you can actually do this in one line of
code:

Dim wordObject As Object = GetObject (Class:="Word.A pplication")

--
Tom Shelton
Sep 11 '06 #3

njuneardave wrote:
Cool, Tom. Thanks!!

I guess I should have used a little less abstraction in this case,
though. Using MS Word was a prelim test. I actually want to test for
the existence of an executable that I made myself called,
"Spectrum.e xe". I first opened the application using:

System.Diagnost ics.Process.Sta rt("Spectrum.ex e")
Now, later in the code, I need to test if my Spectrum.exe is currently
running. Sorry about the abstraction.... I didn't think that it would
play a major role =P Anyway, any new tips?
Thanks so much for the help!
Sure, save the reference to the process that is returned by
Process.Start. Then you can test and see if it is running at
anytime... Look at the process classes HasExited property. It is also
possible to hook an event handler to the process so that your
application get's notified when the process exits.

--
Tom Shelton

Sep 11 '06 #4
Oh, I like that way better, Tom. Thanks for the advice! I appreciate
you.

Tom Shelton wrote:
njuneardave wrote:
Cool, Tom. Thanks!!

I guess I should have used a little less abstraction in this case,
though. Using MS Word was a prelim test. I actually want to test for
the existence of an executable that I made myself called,
"Spectrum.e xe". I first opened the application using:

System.Diagnost ics.Process.Sta rt("Spectrum.ex e")
Now, later in the code, I need to test if my Spectrum.exe is currently
running. Sorry about the abstraction.... I didn't think that it would
play a major role =P Anyway, any new tips?
Thanks so much for the help!

Sure, save the reference to the process that is returned by
Process.Start. Then you can test and see if it is running at
anytime... Look at the process classes HasExited property. It is also
possible to hook an event handler to the process so that your
application get's notified when the process exits.

--
Tom Shelton
Sep 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2129
by: Jean-David Beyer | last post by:
I have six hard drives (4 SCSI and 2 EIDE) on my main machine with parts of a database on each drive. The main index is on one SCSI drive all to itself. The main data are on the other three SCSI drives. Small relations are on one EIDE drive, and the logfiles are on the other EIDE drive. When running the task, below, the rest of the machine is not doing much. I do not remember where I saw it, but somewhere I got the idea that the number...
6
4639
by: pemo | last post by:
Does anyone know of an algorithm that can accurately determine the number of syllables in a given English word - esp. if that word isn't already 'known' by such an algorithm? FYI, there are two approaches I'm currently considering. One is to reduce/convert (somehow) the word into its IPA equivalent, e.g., 'parliament' becomes 'plm()nt' (apologies if that doesn't come out too right!) - parsing that is, I believe, straight forward. ...
7
3888
by: Zeke | last post by:
I'm using the following code to create word document but the problem is if you go to task manager you'll see a WINWORD.EXE process is running but not the application, here is the code: Word.Document aDoc= WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible); WordApp.Visible = true; aDoc.Activate(); WordApp.Selection.TypeText("Hello");
16
1734
by: Simon Verona | last post by:
I have a problem with automating MS Word through vb.net My code is : Dim objword As new Word.ApplicationClass Try objWord.Documents.Open(letterfile) objWord.Documents.Item(letterfile).Activate() Catch MsgBox("Error - Word Not running properly - letterfile=" & letterfile &
6
2408
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side automation. N.B. the environment is a totally enclosed intranet, all the client machines have WinXP, IE6 and Office Pro 2003 with all the latest SPs, and the IE security settings are sufficient to allow the Local Intranet Zone to instantiate...
14
5299
by: Alan T | last post by:
These are the codes I created a document: _WordApp = new Interop.Word.Application(); _WordApp.Visible = false; _WordDoc = new Document(); _Missing = System.Reflection.Missing.Value;
2
4883
by: Derek Hart | last post by:
I am using late bound Microsoft Word integration with a vb.net winforms application. If I run code such as the following: Dim objWord As Object Dim objWrdDoc As Object Dim count As Integer Dim filename As String filename = "c:\temp\mergedata\1.doc" objWord = CreateObject("Word.Application") For count = 1 To 10000
1
6549
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!) upgraded from Access 2000 to Access 2007. Now that component is failing. The merge is building the data source file fine (text file named merge.888). I am providing an absolute path reference to the word file being used for the mail merge. ...
0
891
by: jfking | last post by:
This was cross-posted on the Javascript side of the forums, but this might be something that needs the expertise of a Microsoft developer. I am trying to get the handle on the embedded Word2003 instance that appears inline when opening a document in IE inside a frameset. wordObject = GetObject("Word.Application"); returns an error even when I can clearly see the Word instance displaying a document loaded into the <IFRAME> section of a...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.