Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Baltimore, MD, Maryland, USA
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check to see if File is Open (OFFICE97 SR2)

    Hi Everyone:
    I have a little problem I need help on. I use Private Sub Workbook_Open() to open some workbooks that are needed to run my application. When the user is finished with the application and shuts down, a little sub routine:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    WorkBooks("WorkBook,name").Close

    shuts down the other workbooks. The problem is that some users become aware of the auto-opened Workbooks and decide to shut them down themselves before leaving the program. So, naturally they get an error message.
    I need to add a little IF then statement that skips over the WorkBooks("WorkBook,name").Close statement if the workbook is already closed.
    Thanks for the help.

  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: Check to see if File is Open (OFFICE97 SR2)

    Stephen,

    As any check to see if a file is open would require an On Error statement, you might as well include it in the BeforeClose code :

    On Error Resume Next
    Workbooks("WorkBook.name").Close
    On Error GoTo 0


    That should ignore the error if the file is not open.

    Andrew C

Posting Permissions

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