Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jan 2005
    Location
    Colorado Springs, Colorado, USA
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is file Already Opened? (2000)

    Hi All

    This is probably too easy but,

    Can I do a quick IF (File Already Opened, Then {this}, Else{That})

    Thom

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is file Already Opened? (2000)

    Not directly. But you can do the following:

    <pre>Public Sub WBOpen()
    Public Sub WBOpen()
    Dim oWB As Workbook
    Set oWB = Nothing
    On Error Resume Next
    Set oWB = Workbooks("full path and workbook name")
    On Error GoTo 0
    If Not oWB Is Nothing Then
    ' do what you want to do if the workbook is open
    End If
    End Sub
    </pre>

    Legare Coleman

  3. #3
    Lounger
    Join Date
    Jan 2005
    Location
    Colorado Springs, Colorado, USA
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is file Already Opened? (2000)

    Hmmm...

    I thought that was what I wanted but really what I want is if the file is opened already then continue, if it isn't opened then it needs to be opened.

    (Please don't kick the dog, he's innocent)

    Thom

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Is file Already Opened? (2000)

    Replace

    If Not oWB Is Nothing Then
    ' do what you want to do if the workbook is open
    End If

    with

    If oWB Is Nothing Then
    Set oWB = Workbooks.Open("path_and_name_here")
    End If
    ' code that uses the workbook goes here

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is file Already Opened? (2000)

    Careful what you ask for, you might get it. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    I see Hans has fixed you up.
    Legare Coleman

Posting Permissions

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