Check to see if a file is open in word

  • Thread starter Thread starter Cheese_whiz
  • Start date Start date
C

Cheese_whiz

Hi all,

I need some code that will check and see if word is open, and if it is, let
me check if a document with a name I provide is currently open.

Can anyone direct me? All I need is a start. I'm use to automating word,
but not trying to do these tasks.

Thanks,
CW
 
Update:

I can quickly put together something if I don't mind adding a reference to
the word library, but I've been trying to avoid that since there's a chance
someone will use the app that has an older version of word.

What I'm really not sure about is the difference between creating the word
instance like I would normally do (if I wanted to automate word to create a
document or something) and this situation where I need to find out of an
instance already exists and, if so, work with it's documents collection.

Thanks again,
CW
 
Cheese_whiz,

This is the difference between Early and Late Binding. In any event take a
look at the following 2 links. the first explain what Early and Late binding
are and their differences. The second is an example of late binding to Word
(what you are looking for).

http://word.mvps.org/fAQs/InterDev/EarlyvsLateBinding.htm
http://www.excelguru.ca/node/10#Word
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
Thanks for the reply, Daniel,

I am familiar with early and late binding, but most of my code has been been
predicated on opening new instances of the packages I have automated. This
was a little new.

I do appreciate the links, though. I'll add them to the collection for
future reference.

Thanks again,
CW
 
Hi

I don't think the second part of your question has been answered.....

To check if a specific document is open use something like:

Dim wdApp, docExist
Set wdApp = GetObject(, "Word.Application")
Set docExist = wdApp.ActiveDocument
If docExist.Name = "name of document" Then
.....

with appropriate error capture etc.

The only problem with this is if there is more than one instance of Word
open as the above will just pick up the first it encounters. I haven't yet
worked out how to spin around open instances - perhaps someone else can help.

Cheers.

BW
 
Back
Top