Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How to create a toggle button on the menu? like the Bold, Underline...
button. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Toggle button | Excel Discussion (Misc queries) | |||
Create and Use Button Menu using visual Basic in Excel | Excel Discussion (Misc queries) | |||
Toggle Button | Excel Discussion (Misc queries) | |||
Shortcut Menu With Toggle Control | Excel Programming | |||
Toggle State on Custom Menu | Excel Programming |