Ryan - Application Level Event?
Posted by JAF on July 05, 2000 4:57 AM
Ryan
You responded to my query about "ghosting" toolbar icons and advised that I had to set up an Application Level Event to do this.
I have the following code in a module:
Sub enable_button()
Application.Toolbars("jaftest").ToolbarButtons(1).Enabled = True
End Sub
Sub disable_button()
Application.Toolbars("jaftest").ToolbarButtons(1).Enabled = False
End Sub
Sub count_open_workbooks()
Dim count_workbooks
Dim x As Workbook
On Error Resume Next
Set x = Workbooks("PERSONAL.XLS")
If Err = 0 Then count_workbooks = Workbooks.Count - 1 Else count_workbooks = Workbooks.Count
If count_workbooks < 1 Then Call disable_button Else Call enable_button
End Sub
and the following code in a Class Module:
Public WithEvents AppEvents As Application
Private Sub AppEvents_NewWorkbook(ByVal Wb As Excel.Workbook)
Dim count_workbooks
Dim x As Workbook
On Error Resume Next
Set x = Workbooks("PERSONAL.XLS")
If Err = 0 Then count_workbooks = Workbooks.Count - 1 Else count_workbooks = Workbooks.Count
If count_workbooks < 1 Then Call disable_button Else Call enable_button
End Sub
Private Sub AppEvents_WorkbookBeforeClose(ByVal Wb As Excel.Workbook, Cancel As Boolean)
Dim count_workbooks
Dim x As Workbook
On Error Resume Next
Set x = Workbooks("PERSONAL.XLS")
If Err = 0 Then count_workbooks = Workbooks.Count - 1 Else count_workbooks = Workbooks.Count
If count_workbooks < 1 Then Call disable_button Else Call enable_button
End Sub
Private Sub AppEvents_WorkbookOpen(ByVal Wb As Excel.Workbook)
Dim count_workbooks
Dim x As Workbook
On Error Resume Next
Set x = Workbooks("PERSONAL.XLS")
If Err = 0 Then count_workbooks = Workbooks.Count - 1 Else count_workbooks = Workbooks.Count
If count_workbooks < 1 Then Call disable_button Else Call enable_button
End Sub
Any suggestions as to what I'm doing wrong?
JAF