ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   set toggleButtons to "pressed" by default (https://www.excelbanter.com/excel-programming/417634-set-togglebuttons-pressed-default.html)

shiva

set toggleButtons to "pressed" by default
 
Hi,

I have created a toolbar on Excel 2007. I have set of toggleButtons on the
toolbar.

Im wondering, if i could set anyone of the toggleButton "pressed" when an
excel file is opened.

when I open an excel file, toggleButtons on my custom toolbar on by default
apprear "unpressed". Here's my requirement, is there any procedure to set
these toggleButtons to "pressed" by default.

Regards,
Shiva

egun

set toggleButtons to "pressed" by default
 
This example is from the Excel Help. You can find it by searching for "State
Property". To get it to work when you open Excel, you should place the code
in the "Open" routine of either the workbook you are opening, or your
"PERSONAL.XLS" file. Then, when Excel opens, the code is run and the buttons
on the command bar will be initialized as you desire. HTH.

This example creates a command bar named Custom and adds two buttons to it.
The example then sets the button on the left to msoButtonUp and sets the
button on the right to msoButtonDown.

Dim myBar As Office.CommandBar
Dim imgSource As Office.CommandBarButton
Dim myControl1 As Office.CommandBarButton
Dim myControl2 As Office.CommandBarButton
' Add new command bar.
Set myBar = CommandBars.Add(Name:="Custom", Position:=msoBarTop,
Temporary:=True)
' Add 2 buttons to new command bar.
With myBar
.Controls.Add Type:=msoControlButton
.Controls.Add Type:=msoControlButton
.Visible = True
End With
' Paste Bold button face and set State of first button.
Set myControl1 = myBar.Controls(1)
Set imgSource = CommandBars.FindControl(msoControlButton, 113)
imgSource.CopyFace
With myControl1
.PasteFace
.State = msoButtonUp
End With
' Paste Italics button face and set State of second button.
Set myControl2 = myBar.Controls(2)
Set imgSource = CommandBars.FindControl(msoControlButton, 114)
imgSource.CopyFace
With myControl2
.PasteFace
.State = msoButtonDown
End With




All times are GMT +1. The time now is 09:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com