ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create CommandBar (https://www.excelbanter.com/excel-programming/343451-create-commandbar.html)

Mike[_101_]

Create CommandBar
 
What VBA coding is needed to create a button on the main menu bar for a
shortcut to macro.

thanks in advance!

Mike



Bob Phillips[_6_]

Create CommandBar
 
Dim oCb As CommandBar
Dim oCtl As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtl.Caption = "myButton"
oCtl.Style = msoButtonCaption
oCtl.OnAction = "myMacro"
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike" wrote in message
...
What VBA coding is needed to create a button on the main menu bar for a
shortcut to macro.

thanks in advance!

Mike





Mike[_101_]

Create CommandBar
 
Thanks again for the coding.

One other question.

If I were to put this in the Workbook_Open section to have the shortcut
button created when the workbook is opened then what coding would I put in
the Workbook_BeforeClose section to have the button removed?

Mike.


"Bob Phillips" wrote in message
...
Dim oCb As CommandBar
Dim oCtl As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtl.Caption = "myButton"
oCtl.Style = msoButtonCaption
oCtl.OnAction = "myMacro"
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike" wrote in message
...
What VBA coding is needed to create a button on the main menu bar for a
shortcut to macro.

thanks in advance!

Mike







Bob Phillips[_6_]

Create CommandBar
 
Application.CommandBars("Worksheet Menu Bar").Controls("myButton").Delete

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike" wrote in message
...
Thanks again for the coding.

One other question.

If I were to put this in the Workbook_Open section to have the shortcut
button created when the workbook is opened then what coding would I put in
the Workbook_BeforeClose section to have the button removed?

Mike.


"Bob Phillips" wrote in message
...
Dim oCb As CommandBar
Dim oCtl As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtl.Caption = "myButton"
oCtl.Style = msoButtonCaption
oCtl.OnAction = "myMacro"
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike" wrote in message
...
What VBA coding is needed to create a button on the main menu bar for a
shortcut to macro.

thanks in advance!

Mike










All times are GMT +1. The time now is 05:21 PM.

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