Вопрос

We have developed an excel addin (.xlam) file which contains some basic functions

e.g MySum(a,b) and returns sum that I want etc

Then I saved the file on the network and installed it on the other peoples excel using

File-->Options-->Addins

Made the excel refer to the network addin works like charm. Everybody can use the MySum() function on their local excel applications.

Now I want to take it to the next level, i.e I want to incorporate the same functions on the ribbon menu, For e.g. we create a .exe file user installs it and a menu will appear on users excel Ribbon named MySum ,This will improve the flexibility to add more functions and makes it easy for end user.

I heard and used some third-party software Ribbon menu the same way (using xll file), and I am aware that it could be done through Visual Studio too. I am just trying to get expert Opinion as to what's the best approach for my Scenario.

Any help appreciated!

Это было полезно?

Решение

It is quite easy to make a custom ribbon yourself using the Custom UI editor. Note - this does NOT work on the Mac, as our friends at Microsoft didn't seem to think it important to be able to control the look of add-ins in the same way on both platforms. Buy me a beer some time and I'll tell you what I really think....

Anyway, you don't need the Visual Studio route. Just go to

http://www.rondebruin.nl/win/s2/win001.htm

Ron de Bruin gives an excellent walk-through on how to do this. Just follow the steps - it works. You edit your source code (before converting to addin), adding some XML that describes the ribbon components that you need. You can hide existing components, add new groups to existing ribbons, create your own tab... It's even quite easy to make good looking icons so your buttons look cool / personalized / professional (I used Axialis icon workshop to design some icons I was rather proud of....)

If you get stuck, ask!

update here is an example of an XML that produces a new tab right after the Home tab, and puts two groups of buttons:

<mso:customUI xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
  <mso:ribbon>
  <mso:qat /> 
    <mso:tabs>
      <mso:tab id="myTab" label="Awesome functions" insertAfterMso="TabHome">
        <mso:group id="myGroup1" label="Awesome math" autoScale="true">
          <mso:button id="id_sum" label="sum" image="sigma" size="large" onAction="UI_doMath" /> 
          <mso:button id="id_mult" label="multiply" image="times" size="large" onAction="UI_doMath" /> 
          <mso:button id="id_var" label="variance" image="variance" size="large" onAction="UI_doMath" /> 
        </mso:group>
        <mso:group id="myGroup2" label="Awesome text" autoScale="true">
          <mso:button id="id_bold" label="really bold" image="bold" size="large" onAction="UI_doText" /> 
          <mso:button id="id_italic" label="italicize" image="italic" size="large" onAction="UI_doText" /> 
        </mso:group>
      </mso:tab>
    </mso:tabs>
  </mso:ribbon>
</mso:customUI>

As you can see, each group calls its own function - one group calls UI_doMath and the other calls UI_doText. The signature of the subs would look a bit like this:

Sub UI_doMath(controlID As String)

Select Case controlID
  Case "id_sum"
    call sumTheStuff
  Case "id_mult"
    call multiplyStuff
  Case "id_var"
    call computeVariance
  Case Else
    MsgBox "Unknown button: '" & controlID & "' was clicked!"
    Exit Sub
  End Select

End Sub

In this way, a single routine is the entry point for all of the buttons in a group in the ribbon. Makes the code a little more maintainable, I think. For me it was particularly so since I actually had a "platform independent" version of this - that is, whether you picked an item from a menu (on Mac) or ribbon (on PC), you ended up in the same functions. But that's a refinement I hope you don't need.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top