+ Reply to Thread
Results 1 to 3 of 3

prohibit closing a workbook

  1. #1
    Christophero
    Guest

    prohibit closing a workbook

    Hi,

    I have a program that uses 2 workbooks. Both must be visible. But the code
    workbook with the graphics cannot be closed by the right corner cross
    clicking.

    How can i prevent this from happening.

    The code workbook closes automaticcly by closing the other data workbook

    Thenks for helping me out

  2. #2
    Jason Morin
    Guest

    Re: prohibit closing a workbook

    Place this in the ThisWorkbook module of the target
    workbook:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Cancel = True
    End Sub

    ---
    HTH
    Jason
    Atlanta, GA

    >-----Original Message-----
    >Hi,
    >
    >I have a program that uses 2 workbooks. Both must be

    visible. But the code
    >workbook with the graphics cannot be closed by the right

    corner cross
    >clicking.
    >
    >How can i prevent this from happening.
    >
    >The code workbook closes automaticcly by closing the

    other data workbook
    >
    >Thenks for helping me out
    >.
    >


  3. #3
    JulieD
    Guest

    Re: prohibit closing a workbook

    Hi Christophero

    this code will stop the workbook closing if "book3" is open (change the name
    as required)
    ---
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error GoTo err_handler
    If Len(Application.Workbooks("Book3.xls").Name) > 0 Then
    Cancel = True
    End If
    err_handler:
    End Sub
    ---
    to use the code, right mouse click on a sheet tab of the book you do not
    want to be able to close directly, choose view code
    to display the vbe window, on the left you should see your workbook's name
    in bold and under that sheet1, sheet2 etc (if you can't see this choose view
    / project explorer from the menu)
    under the workbook's name you should see ThisWorkbook - double click on
    ThisWorkbook and copy & paste the code into the right hand side of the
    screen.
    now use alt & F11 to switch back to your workbook and attempt to close the
    book. it should not be possible while the other book is open.

    i hope this will work in with your current code.

    --
    Cheers
    JulieD
    check out www.hcts.net.au/tipsandtricks.htm
    ....well i'm working on it anyway
    "Christophero" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I have a program that uses 2 workbooks. Both must be visible. But the code
    > workbook with the graphics cannot be closed by the right corner cross
    > clicking.
    >
    > How can i prevent this from happening.
    >
    > The code workbook closes automaticcly by closing the other data workbook
    >
    > Thenks for helping me out




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1