Solved

VBA: Migrating from toolbars to ribbon

Posted on 2014-01-11
9
244 Views
Last Modified: 2014-10-25
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
0
Comment
Question by:Saqib Husain, Syed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 39774869
You really can't convert it directly. VBA Ribbons are built with XML, so you'd have to create your Ribbon XML and then set the OnAction method to manage the actions you want to take when the user clicks your ribbon. Generally you add Functions/Subs or Macros, and call those Functions, Subs or Macros.

Many Access developers like this tool:

http://www.ribboncreator.de/en/ (2007)
http://www.ribboncreator2010.de/en/ (2010)

It creates your ribbons, adds the necessary modules to the VBA project, etc etc. It's by far the simplest way to work with Ribbons, and it works in Access, Excel or Word.
0
 
LVL 101

Assisted Solution

by:mlmcc
mlmcc earned 250 total points
ID: 39775084
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39810528
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.
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 85
ID: 39810574
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.
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39811047
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.
0
 
LVL 85
ID: 39811744
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
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39811774
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.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40403794
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question