Charlie,
The code I paste here is from a VBA app that I wrote a while back. It has the common menu structures. You should be able to modify it to fit your requirements.
Sub AddV2Menu()
Set cbWSMenuBar = Application.CommandBars("Worksheet Menu Bar")
'the Excel menu bar name to which your control will be added
Set muCustom1 = cbWSMenuBar.Controls.Add(Type:=msoControlPopup)
With muCustom1
.BeginGroup = True 'places line to left of menu item
.Caption = "DMFi&le"
With .Controls.Add(Type:=msoControlPopup)
.Caption = "&Open DMGraphic files"
.OnAction = ""
'OPEN FILE SUB MENU
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Summary..."
.OnAction = "OpenSumaryFile"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&DataBase..."
.OnAction = "OpenDatabaseFile"
End With
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&General preferences..."
.OnAction = "DisplayGeneralPrefs"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Links"
.OnAction = "DisplayLinks"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Exit MFStandard"
.OnAction = "LeaveDMGaphics"
.BeginGroup = True 'places line above menu item
End With
End With
End Sub
Sub RemoveBar()
Application.CommandBars("Worksheet Menu Bar").Controls("DMFile").Delete
End Sub
Dave Gathmann
--- In ExcelVBA@yahoogroups.com, railroads@... wrote:
>
>
> HI
>
> Courtesy of Contextures I am using the code below for a floating toolbar. Works well. However I would like to be able to have the toolbar appear on the same as the menu row. With File,Edit,View. etc.
> When I drag it up it will only go on its own row above or below the menu row. Is it possible to attach somehow ?
> Can the new toolbar be made to work as a dropdown. That is when you click on the name a drop down of the items appears and you select item required.
>
> Thankyou
>
> Charlie Harris
>
> *******************
> Option Explicit
>
> Public Const ToolBarName As String = "MyToolbarName"
> '===========================================
> Sub Auto_Open()
> Call CreateMenubar
> End Sub
>
> '===========================================
> Sub Auto_Close()
> Call RemoveMenubar
> End Sub
>
> '===========================================
> Sub RemoveMenubar()
> On Error Resume Next
> Application.CommandBars(ToolBarName).Delete
> On Error GoTo 0
> End Sub
>
> '===========================================
> Sub CreateMenubar()
>
> Dim iCtr As Long
>
> Dim MacNames As Variant
> Dim CapNamess As Variant
> Dim TipText As Variant
>
> Call RemoveMenubar
>
> MacNames = Array("aaa", _
> "bbb")
>
> CapNamess = Array("AAA Caption", _
> "BBB Caption")
>
> TipText = Array("AAA tip", _
> "BBB tip")
>
> With Application.CommandBars.Add
> .Name = ToolBarName
> .Left = 200
> .Top = 200
> .Protection = msoBarNoProtection
> .Visible = True
> .Position = msoBarFloating
>
> For iCtr = LBound(MacNames) To UBound(MacNames)
> With .Controls.Add(Type:=msoControlButton)
> .OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
> .Caption = CapNamess(iCtr)
> .Style = msoButtonIconAndCaption
> .FaceId = 71 + iCtr
> .TooltipText = TipText(iCtr)
> End With
> Next iCtr
> End With
> End Sub
>
> '===========================================
> Sub AAA()
> MsgBox "aaa"
> End Sub
>
> '===========================================
> Sub BBB()
> MsgBox "bbb"
> End Sub
>
> *************************
>
Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (2) |
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------
Tidak ada komentar:
Posting Komentar