Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How to create a toggle button on the menu?

How to create a toggle button on the menu? like the Bold, Underline...
button.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to create a toggle button on the menu?

Hi OKLover,

"OKLover" wrote in message
...
How to create a toggle button on the menu? like the Bold, Underline...
button.


Add a toolbar button and then assign toggle code to the button.

For example, the following code toggles the visible state of columns A:D on
the active sheet:

Sub ToggleColumnHide()
Dim rng As Range

Set rng = ActiveSheet.Columns("A:D")

rng.Hidden = Not rng.Hidden

End Sub


---
Regards,
Norman



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How to create a toggle button on the menu?

Norman, thanks for your answer. My question is that i know how to create a
menu item as below:


With CommandBars.Add(Name:="MyCheckButton", Position:=msoBarPopup)
With .Controls.Add(Type:=????????)
.OnAction = "someprocedure"
.Caption = "TheMenuItemName"
End With
End With

But it could not be toggled or checked. What's the control type i should
assign to it?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to create a toggle button on the menu?

Try the following code. It will add an item to the Tools menu.

Sub AddControl()

Dim Ctrl As Office.CommandBarButton
Set Ctrl = Application.CommandBars.FindControl(ID:=30007) _
.Controls.Add(temporary:=True)
With Ctrl
.Caption = "Click Me"
.State = msoButtonUp
.Visible = True
.OnAction = "'" & ThisWorkbook.Name & "'!TheMacro"
End With

End Sub

Sub TheMacro()

With Application.CommandBars.ActionControl
If .State = msoButtonUp Then
.State = msoButtonDown
Else
.State = msoButtonUp
End If
End With

MsgBox "Hello, World"

End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"OKLover" wrote in message
...
How to create a toggle button on the menu? like the Bold,
Underline... button.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How to create a toggle button on the menu?

Chip, you saved my life ~ many thanks :D


"Chip Pearson" ...
Try the following code. It will add an item to the Tools menu.

Sub AddControl()

Dim Ctrl As Office.CommandBarButton
Set Ctrl = Application.CommandBars.FindControl(ID:=30007) _
.Controls.Add(temporary:=True)
With Ctrl
.Caption = "Click Me"
.State = msoButtonUp
.Visible = True
.OnAction = "'" & ThisWorkbook.Name & "'!TheMacro"
End With

End Sub

Sub TheMacro()

With Application.CommandBars.ActionControl
If .State = msoButtonUp Then
.State = msoButtonDown
Else
.State = msoButtonUp
End If
End With

MsgBox "Hello, World"

End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"OKLover" wrote in message
...
How to create a toggle button on the menu? like the Bold, Underline...
button.





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
Toggle button keithl816 Excel Discussion (Misc queries) 2 November 21st 05 09:16 PM
Create and Use Button Menu using visual Basic in Excel Walter L. skinner Excel Discussion (Misc queries) 3 November 17th 05 11:40 AM
Toggle Button Dave_2k5 Excel Discussion (Misc queries) 2 September 1st 05 11:27 AM
Shortcut Menu With Toggle Control quartz[_2_] Excel Programming 0 February 10th 05 02:23 PM
Toggle State on Custom Menu Devin McMahon Excel Programming 0 July 23rd 03 02:36 AM


All times are GMT +1. The time now is 04:38 AM.

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

About Us

"It's about Microsoft Excel"