Your use of On Error Resume Next as the top hides all the errors in your
code. You may have more problems than this, but these untested changes may
help. I assumed the commandbar you speak of is the worksheet menu bar. If
not, make appropriate adjustments.
Sub en()
Dim c As Variant
'On Error Resume Next
With Application
.CommandBars.ActiveMenuBar.Enabled = True
For Each c In .Commandbars("Worksheet Menu Bar").Controls
If c.Caption = "EN" Then c.Delete
Next c
set cb = .CommandBars("Worksheet Menu Bar").Controls.Add( _
Type:=msoControlButton, Id:=2950, befo=1)
cb.Caption = "EN"
cb.TooltipText = "Enable Events"
cb.OnAction = ThisWorkbook.Name & "!enevents"
cb.Style = msoButtonCaption
Worksheets("hidden").Visible = True
End With
End Sub
--
Regards,
Tom Ogilvy
"Simon Lloyd " wrote in message
...
I have this code for creating a toggle button to turn events on and off,
i call on this sub (Call en) in a procedure that says if the admin
password is ???? then with the application show command bars end with
and after that i use Call en it does not fault but it does not create a
button on the command bar, any ideas??
Simon.
Here's all the code im using
Sub en()
Dim c As Variant
On Error Resume Next
With Application
CommandBars.ActiveMenuBar.Enabled = True
For Each c In .Controls
If c.Caption = "EN" Then c.Delete
Next c
Controls.Add Type:=msoControlButton, Id:=2950, befo=1
Controls(1).Caption = "EN"
Controls(1).TooltipText = "Enable Events"
Controls(1).OnAction = ThisWorkbook.Name & "!enevents"
Controls(1).Style = msoButtonCaption
Worksheets("hidden").Visible = True
End With
End Sub
Private Sub TextBox1_Change()
If TextBox1.Text = "????" Then
With Application
CommandBars.ActiveMenuBar.Enabled = True
End With
Call en
ElseIf TextBox1.Value < "????" Then
Exit Sub
End If
Unload Me
'Me.Hide
End Sub
Sub enevents()
Application.EnableEvents = Not Application.EnableEvents
End Sub
---
Message posted from http://www.ExcelForum.com/