Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Disabling/enabling events with a button created by code??

Hello all!,

I have created a custom button that when clicked displays all hidde
sheets and also displays the worksheet menu bar, what i would like t
happen is that when this button is clicked that along with the above
new button appears on the menubar marked disable/enable, so that whe
this button is clicked it disables events for that sheet and whe
clicked again enables events!

Thanks,

Simon

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Disabling/enabling events with a button created by code??

Hi Simon

Incorporate the following into your existing sub to create the new button...

--------------------
Dim c As Variant
With Application.CommandBars("Worksheet Menu Bar")
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
End With
End Sub
--------------------

and add this new sub....

Sub enevents()
Application.EnableEvents = Not Application.EnableEvents
End Sub



--
XL2002
Regards

William



"Simon Lloyd " wrote in message
...
| Hello all!,
|
| I have created a custom button that when clicked displays all hidden
| sheets and also displays the worksheet menu bar, what i would like to
| happen is that when this button is clicked that along with the above a
| new button appears on the menubar marked disable/enable, so that when
| this button is clicked it disables events for that sheet and when
| clicked again enables events!
|
| Thanks,
|
| Simon.
|
|
| ---
| Message posted from
http://www.ExcelForum.com/
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Disabling/enabling events with a button created by code??

Thanks for that William!

Will this code work in xl97?...sorry forgot to mention that!

Simo

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Disabling/enabling events with a button created by code??

Hi Simon

I think so but unsure as tested in XL2002

--
XL2002
Regards

William



"Simon Lloyd " wrote in message
...
| Thanks for that William!
|
| Will this code work in xl97?...sorry forgot to mention that!
|
| Simon
|
|
| ---
| Message posted from
http://www.ExcelForum.com/
|



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Disabling/enabling events with a button created by code??

Hi William,

Well i tried your code and inserted it word for word only i kee
getting an error saying method of class is unsupported!, when i debu
it tells me that "c" is empty, any ideas what im doing wrong!

Simo

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Disabling/enabling events with a button created by code??

Hi Simon

Try this....

--------------------
Dim c As Variant
On Error Resume Next
With Application.CommandBars("Worksheet Menu Bar")
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
End With
End Sub
--------------------

--
XL2002
Regards

William



"Simon Lloyd " wrote in message
...
| Hi William,
|
| Well i tried your code and inserted it word for word only i keep
| getting an error saying method of class is unsupported!, when i debug
| it tells me that "c" is empty, any ideas what im doing wrong!
|
| 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
enabling/disabling a set of code from within a spreadsheet sheet Roger on Excel Excel Discussion (Misc queries) 2 November 17th 07 05:04 PM
Enabling Events Robin Clay Excel Discussion (Misc queries) 8 July 12th 06 03:07 PM
Disabling code using a button? Simon Lloyd[_505_] Excel Programming 6 June 23rd 04 02:16 PM
Disabling/Enabling Macros HRobertson Excel Programming 2 October 24th 03 04:07 PM
Enabling/Disabling Macros David Excel Programming 6 August 12th 03 06:21 PM


All times are GMT +1. The time now is 02:34 PM.

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"