Re: Checking if a Word file is open

From: NEtsdpace news (cde.support_at_cde-pl.com.au)
Date: 04/29/04


Date: Fri, 30 Apr 2004 09:18:29 +1000

Do you know how to check if a file is open at all, not just whether the
local machine has the file open? From what I can make out here it checks
whether the local machine has the file open by seeing if there is an open
instance of word and if so checking the list of files open to see if any of
their names match the desired file. What if another machine has the file
open or its not a Word file?

"GoGoGadgetScott" <gogogadgetscott@hotmail.com> wrote in message
news:opr61pfs0i9xhenz@onthego.bflony.adelphia.net...
Function DocOpen(sFile)
'Get an existing instance of the Word object, if one exists
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
'Word is not open
If Err.Number = 429 Then Exit Function
On Error GoTo 0
'If an instance of word is found we can loop though the collection of
documents
For Each Document in oWord.Documents
If Document.FullName = sFile Then
'Match is made, documnet is open in Word
DocOpen = True
'Found what we were looking for, lets get out of here
Exit For
End If
Next
'We can now control the open document
If DocOpen Then
'This works becouse we used the Exit for
Document.Close
'Else would could find our document like this:
'oWord.Documents(sFile).Close
'Don't use both, we cannot close a doc twice
End If
'Close up word if there are no open docs
If oWord.Documents.Count = 0 Then oWord.Quit
'Clean up out mess
Set oWord = Nothing
End Function

'Full path of file we are checking to determine if open
sFile = "C:\Untitled.doc"
'Output results
If DocOpen(sFile) Then
MsgBox sFile & " was open, but now closed"
Else
MsgBox sFile & " is not open"
End If

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Relevant Pages

  • Re: Application ExitCode
    ... > I've created a Windows Script that opens the MDB ... > application on the local machine and waits for it to ... > exit, storing the objects exitcode. ...
    (microsoft.public.access.modulesdaovba)
  • Re: first ssh, then start copying
    ... >exit, remembering the location of the files I want to copy, and scp ... >from the local machine to get the files. ...
    (comp.security.ssh)