Link to home
Start Free TrialLog in
Avatar of Saqib Husain
Saqib HusainFlag for Pakistan

asked on

VBA: Migrating from toolbars to ribbon

How can I convert this code from the toolbar system to the ribbon system with particular reference  to excel?

Sub toolbr()
Dim cbrCmdBar       As CommandBar
Dim strCBarName     As String
On Error Resume Next
Application.CommandBars("Retaining wall").Delete
On Error GoTo 0
strCBarName = "Retaining Wall"
Set cbrCmdBar = Application.CommandBars.Add(Name:=strCBarName)
Call addcommbutt(cbrCmdBar, 4, "Print", "Print selected sheets", "sheet1.PrtMenu")
Call addcommbutt(cbrCmdBar, 23, "Open", "Load data", "sheet1.DataOpen")
Call addcommbutt(cbrCmdBar, 6113, "SavNew", "Save as new data", "sheet1.SavNew")
Call addcommbutt(cbrCmdBar, 3, "SavCur", "Save to current data", "sheet1.SavCurr")
Call addcommbutt(cbrCmdBar, 402, "Fit", "Fit width", "sheet1.FitWidth")
Call addcommbutt(cbrCmdBar, 498, "Data", "Goto data sheet", "sheet1.DataSht")
Call addcommbutt(cbrCmdBar, 198, "Stability", "Goto Stability page", "sheet1.StabSht")
Call addcommbutt(cbrCmdBar, 212, "Design", "Goto design Page", "sheet1.DgnSht")
Call addcommbutt(cbrCmdBar, 134, "Top", "Goto top of sheet", "sheet1.TopSht")
cbrCmdBar.Visible = True
End Sub
Sub addcommbutt(cbrCmdBar, fid, cap, ttip, macr)
Dim a As CommandBarButton
Set a = cbrCmdBar.Controls.Add(Type:=msoControlButton)
a.Caption = cap
a.FaceId = fid
a.OnAction = macr
a.Style = msoButtonIconAndCaption
a.TooltipText = ttip
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Saqib Husain

ASKER

Could there be a workaround? I want to have something which works itself. I do not want to be installing things when moving to another computer.
I want to have something which works itself
Not sure what you mean by that. You can edit XML with any standard editing tool (Notepad, for example), so you don't have to have anything in particular.

That said, the Ribbon Creator is a tool, like anything else. You would install that on your development machine and create your ribbons there, and then transfer the completed ribbons with your workbooks or databases.
install that on your development machine ....then transfer the completed ribbons with your workbooks
Just what I do not want to do. It used to be within the workbook on 2003 and all the user had to do was to enable macros. I must have something (maybe a workaround) for which the other user does not have to do something special.
You don't have to use the Ribbon Creator. You can create your ribbon XML with Notepad, if you like. It's just much, much easier to use a tool like that, since it gets the syntax exactly right.

You do need to add these as "addins", which essentially insert the .xml into your Excel file. That xml would travel with your Excel document, and you'd use VBA code to show the ribbon when needed.

Also see this page: http://www.rondebruin.nl/win/s2/win001.htm
I am not going into that. I would prefer to have a frozen area at the top of the sheet and insert buttons there which would do the same task...all within the workbook.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.