You can trap an application level event for this
Here's an example XLA
1) start a new workbook.
2) add a class module,name it clXL
3) in the class module code page addthis
Option Explicit
Private WithEvents xl As Excel.Application
Private Sub xl_WorkbookBeforeClose(ByVal Wb As Workbook, _
Cancel
As Boolean)
Cancel = _
(MsgBox("OK", vbYesNo, "Closing " & Wb.Name) = vbNo)
End Sub
Private Sub Class_Initialize()
Set xl = Excel.Application
End Sub
4) add a standard code module
5) in the code sheet of the standard code module add this code:
Option Explicit
Public xl As clXL
Sub Auto_Open()
Set xl = New clXL
End Sub
6) save the workbook as an XLA, remember where as we'll open it again soon!
close excel
Open excel.
with the add-in manager open the XLA...browse to it if need be
When the add-in opens, the auto_open sub creates the variable set to the
open instance of excel.
Closing a workbook or excel itself will raise a message.
This is a simple example to demonstrate how simple it is to use application
level events.
"Tempy" wrote:
> Hi all,
>
> I have written some code that automatically hides all tool bars on
> opening. I then have an exit button that takes it to some more code that
> shows the tool bars again. However some people have closed the workbook
> by just clicking on the "X" close button which does not repair the
> workbook and when they re-open exel the tool bars are not there !!
> Is it possible to either hide or deactivate the "X" button ?
>
> Thanks for all the help on my last queries
>
> Tempy
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
Bookmarks