ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   prohibit closing a workbook (https://www.excelbanter.com/excel-discussion-misc-queries/20449-prohibit-closing-workbook.html)

Christophero

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

Jason Morin

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
.


JulieD

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" wrote in 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





All times are GMT +1. The time now is 02:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com