Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help! File in USE (VB/VBA/API)

    If somebody knows how programmatically find out word document is already open by other user. Document is located on a network drive. Windows NT give a message "File In Use....." I want to know this information before calling Documents.Open(FILENAME).
    Thanks

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help! File in USE (VB/VBA/API)

    You have several options, none of which is as refreshing
    as an ice cold beer after a lot of yard work.

    1) Test for the presence of the temp file (e.g.,
    ~$openfilename.doc). If that file exists, it's "parent" is in
    use. You can even open that temp file and parse out the
    name of the user who has it open.

    2) Use the VB(A) OPEN command to test for write access.
    Here's my version of that approach with ample gleanings from other notable posters. I'm simply copying and
    pasting from a class mod, so you'll need to tweek the code
    to make a standalone function:

    Function FileInUse(strFileName As String) As Boolean
    'Tests for Permission the InUse status of file
    pFullName = strFileName
    On Error Resume Next
    Open pFullName For Binary Access Read Write Lock Read Write As #1
    Close #1
    Select Case Err.Number
    Case 53 'File not found
    MsgBox "The file does not exists.", vbCritical, "clsFSO - FileInUse Error"
    Case 75 'Path/File Access error
    Case 70 'Permission Denied
    End Select
    FileInUse = Err.Number
    End Function

    By the way, if you do a search on this forum, you'll find other
    posts about this topic, one of which is one of mine which is
    WRONG. Don't use the FileSystemObject's OpenTextFile
    method in place of the VB OPEN statement. Bad things will
    happen.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    New Lounger
    Join Date
    May 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help! File in USE (VB/VBA/API)

    Thanks a lot Kevin. I tried the first option.(OPEN) It works!!!
    I was thinking to use tmp file before, but it is little complicated because tmp name for long file names is different from original name file~$cuttedname.doc
    Thanks again,
    Alik <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

  4. #4
    Star Lounger
    Join Date
    Apr 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help! File in USE (VB/VBA/API)

    Check out the MVPS site (mvps.org). They have a snippet of code for this at:

    http://www.mvps.org/word/FAQs/Macros...IfFileOpen.htm

    Good luck.

    Texas TJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •