Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is File Open? (XL97:SR2)

    I have an issue where it looks as if the path produces the problem in the following code:

    Sub IsWorkBookOpen()
    Dim wBook As Workbook
    On Error Resume Next
    Set wBook = Workbooks("YourFile.xls")

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Is File Open? (XL97:SR2)

    < It does not make sense that once you put in a path to the file the code does not recoginze the file as being open >

    I'm not sure about that as you cannot have two workbooks with the same filename open concurreently, even they have different paths. The path is a modifiable property of the workbook so cannot be used to absolutely identify the workbook object.

    Hope that makes sense.

    Andrew C

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is File Open? (XL97:SR2)

    Andrew,

    Under the scenario that I am working with only one file would be open. I though it would be possible to test if a workbook (located say on Server [img]/forums/images/smilies/cool.gif[/img] is open from a workbook on Server A that contains the code to do the testing. If I point the path as if I were opening the workbook on Server B and don't put the path in the code "It Works". I'm still confused.

    John

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Is File Open? (XL97:SR2)

    I'm afraid the bst you can do is test for a worbook named YourFile.xls, and if found test to see if the path points to Server B. Excel identifies it's workbooks by their names - the path is just an incidental property that points to the path name of the file.

    Andrew

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Is File Open? (XL97:SR2)

    If you want to check the full name, you can loop through the Workbooks collection using a numeric index:

    For intCounter = 1 to Workbooks.Count
    if Workbooks(intCounter).FullName = "whatever" Then
    blnFoundIt = True
    Workbooks(intCounter).Activate
    Exit For
    End if
    Next
    if Not blnFoundIt Then
    MsgBox "Error..."
    Exit Sub
    End if

    Or something like that. (note: I didn't test this.)

Posting Permissions

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