Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Code to handle files that are already open

  1. #1
    New Member
    Join Date
    Mar 2002
    Location
    Paul
    Posts
    34
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi all,

    Does anybody know the syntax for an IF STATEMENT to check if an Excel workbook is already open?

    I have a form that opens 5 workbooks before performing various tasks. I want to avoid the message "xyz is already open. Re-opening will cause any changes you made to be discarded. Do you want to reopen xyz?".

    Any Thoughts?

    Many Thanks.

    Cheers - Paul

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Posts
    363
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try this:

    Sub OpenFile()
    wb = "C:My Documentsxyz.xls"
    For Each wbk In Workbooks
    If wbk.FullName = wb Then
    Windows(wbk.Name).Visible = True
    wbk.Activate
    GoTo endsub
    End If
    Next wbk
    Workbooks.Open Filename:=wb
    endsub:
    End Sub

    This will unhide and activate the file if it's open or open it if it's not.
    It's never too late to learn something new.

    Ricky

  3. #3
    New Member
    Join Date
    Mar 2002
    Location
    Paul
    Posts
    34
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Many Thanks Ricky!

    PROBLEM SOLVED

    Cheers - Paul

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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