D
Dan
I run several reports with ledger data and journal data. I added a right
click drop down allowing a user to look up journals from the ledger data.
All works well except for .... I added a 'before close' piece of code to
delete the drop down items - don't wish them to be there if the file is not
in use. I assumed only one file would be open at a time - wrong. If a
second file is opened and either the first or second is closed, the menu
items go away. Is there an easy way to interrogate the open files and leave
the drop down if a file that needs it is open?
Module Code
Sub see_journals()
a = ActiveCell.Column
X = ActiveCell.Value
If a <> 4 Or X = "" Then
MsgBox "Please place your cursor on an account number."
Exit Sub
End If
Worksheets("Journal Details").Select
Range("Journal").Select
Selection.AutoFilter Field:=5, Criteria1:=X
End Sub
Sub NewItem()
On Error GoTo ONE
If CommandBars("Cell").Controls("See Journals").Visible Then
Exit Sub
End If
ONE:
Dim ThisItem As Object
Set ThisItem = CommandBars("Cell").Controls.Add
With ThisItem
..Caption = "See Journals"
..OnAction = "See_Journals"
..BeginGroup = True
End With
End Sub
Sub RidIt()
On Error Resume Next
CommandBars("Cell").Controls("See Journals").Delete
End Sub
ThisWorkbook Code
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RidIt
End Sub
click drop down allowing a user to look up journals from the ledger data.
All works well except for .... I added a 'before close' piece of code to
delete the drop down items - don't wish them to be there if the file is not
in use. I assumed only one file would be open at a time - wrong. If a
second file is opened and either the first or second is closed, the menu
items go away. Is there an easy way to interrogate the open files and leave
the drop down if a file that needs it is open?
Module Code
Sub see_journals()
a = ActiveCell.Column
X = ActiveCell.Value
If a <> 4 Or X = "" Then
MsgBox "Please place your cursor on an account number."
Exit Sub
End If
Worksheets("Journal Details").Select
Range("Journal").Select
Selection.AutoFilter Field:=5, Criteria1:=X
End Sub
Sub NewItem()
On Error GoTo ONE
If CommandBars("Cell").Controls("See Journals").Visible Then
Exit Sub
End If
ONE:
Dim ThisItem As Object
Set ThisItem = CommandBars("Cell").Controls.Add
With ThisItem
..Caption = "See Journals"
..OnAction = "See_Journals"
..BeginGroup = True
End With
End Sub
Sub RidIt()
On Error Resume Next
CommandBars("Cell").Controls("See Journals").Delete
End Sub
ThisWorkbook Code
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RidIt
End Sub