Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determining if a file is open

4 views
Skip to first unread message

Neil

unread,
Oct 30, 2007, 1:57:06 PM10/30/07
to
I am trying to determine if a Word doc is open, because I have a process
that looks to open it, save it in a different format, and then move on to
another doc.

I tried using the command:

If Dir(strFilePath & "~$" & strfilename, vbHidden) <> "" Then
'Skip file
End if

to use the "~$" file to determine if it's open. This worked fine on my PC.
However, when I tried it on the network, it didn't work.

I need to be able to determine if a file is open, either by using Dir(), or
by using some method within Word. Since the files are open across a network,
I can't check the open documents in my copy of Word. Any ideas? Using Word
2000.

Thanks!

Neil


jan

unread,
Oct 30, 2007, 2:38:52 PM10/30/07
to
Neil,

This is a way doing it:

Function DocIsOpen(strFullName As String)
Dim wrdDoc As Word.Document
Dim blnResult As Boolean
For Each wrdDoc In Word.Documents
If StrComp(wrdDoc.FullName, strFullName, vbTextCompare) = 0 Then
blnResult = True
Exit For
End If
Next
DocIsOpen = blnResult
End Function

You can use this function in this way:

docisopen("D:\Data\Discussieforum\Test\test.doc")

so use the fullname.


Jan


Neil

unread,
Oct 30, 2007, 11:24:51 PM10/30/07
to
As I noted in my message, I am doing this across a network, so checking
which documents are open in my instance of Word doesn't do me any good. I
need to know if the document is open, period, by anyone on the network, not
just by me.


"jan" <j...@releerf.nl> wrote in message
news:ei6DdQyG...@TK2MSFTNGP03.phx.gbl...

Shauna Kelly

unread,
Oct 31, 2007, 2:34:13 AM10/31/07
to
Hi Neil

See http://www.word.mvps.org/FAQs/MacrosVBA/CheckIfFileOpen.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"Neil" <nos...@nospam.net> wrote in message
news:YASVi.3528$Vx3....@nlpi069.nbdc.sbc.com...

Neil

unread,
Oct 31, 2007, 9:43:40 AM10/31/07
to
Thanks, Shauna. That would work. Only one thing I failed to mention
previously: this process will be running nightly on my development machine,
and on that machine I have error handling turned off. So that means the
process would break each time a file's not found.

I suppose I can turn error handling on at the beginning of the process and
then off again at the end (which would be OK as long as it didn't crash in
the middle). So, if I have to, I'll do that. Still, a solution that didn't
require error handling to be on would be better still.

Any idea why my original Dir() solution worked on my local machine to find
the ~$ file, but didn't work across the network?

Thanks!

Neil


"Shauna Kelly" <Shaun...@SendNoSpamToShaunaKelly.com> wrote in message
news:%23uQF8i4...@TK2MSFTNGP02.phx.gbl...

Jonathan West

unread,
Oct 31, 2007, 1:41:13 PM10/31/07
to

"Neil" <nos...@nospam.net> wrote in message
news:SfKVi.51769$RX.2...@newssvr11.news.prodigy.net...

>I am trying to determine if a Word doc is open, because I have a process
>that looks to open it, save it in a different format, and then move on to
>another doc.
>

Try this

How to check if a file has already been opened by another user
http://www.word.mvps.org/FAQs/MacrosVBA/CheckIfFileOpen.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

0 new messages