Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why does this code not create a button when called???

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/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why does this code not create a button when called???

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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why does this code not create a button when called???

Thanks again Tom it worked a treat......one other querie?, how do i ge
the button to show suken or raised or perhaps highlighted or shadowe
when it is clicked so the user can see if it has been toggled?

Simon

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why does this code not create a button when called???

Perhaps you mean this:

http://support.microsoft.com/default...35&Product=xlw
XL2000: How to Place a Check Mark Next to a Custom Menu Item

--
regards,
Tom Ogilvy

"Simon Lloyd " wrote in message
...
Thanks again Tom it worked a treat......one other querie?, how do i get
the button to show suken or raised or perhaps highlighted or shadowed
when it is clicked so the user can see if it has been toggled?

Simon.


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a form to insert a hyerlink.VBA code to create a for karthi Excel Discussion (Misc queries) 0 July 5th 06 11:26 AM
Returning From VBA Event Code Called From Excel 4.0 Macro jj Excel Programming 0 July 12th 04 04:30 PM
Help! Code jump to function with out being called??? Chrissy[_4_] Excel Programming 0 October 12th 03 12:07 AM
Save Event - Determine if called by code or user David Sedberry Excel Programming 0 October 2nd 03 04:56 PM
Create Command Button from Code Bruce B[_2_] Excel Programming 0 July 14th 03 02:01 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"