Add standard command button “New Slide” to custom ribbon in office add-in

前端 未结 5 1227
盖世英雄少女心
盖世英雄少女心 2021-01-27 17:59

I have created my customized ribbon in an addIn. Now I would like to add the New Slide command that exist in home screen (see screenshot below)

相关标签:
5条回答
  • 2021-01-27 18:07

    I created a new ribbon based on xml Template in VS. Afterwards I added a group and a control based on an idMso-Value. When using this xml file

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="tab0" label="AddIn">
            <group id="grpCustom">
              <button idMso="SlideNew" size="large" label="YOUR CUSTOM TEXT"></button>
            </group>
            <group idMso="GroupSlides"></group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    This results in that custom ribbon. Eugene Astafiev pointed it out, you can find idMso-Values in MSDN.

    customized ribbon controls

    0 讨论(0)
  • 2021-01-27 18:17

    As explained by Franz the solution is to use the idMso. For the New Slide command you are looking for, if you look at MSN in the idMso Table for "New Slide" you will find two entries. The one you are looking for is a Gallery with idMso=SlideNewGallery. (not a button). You can add it in the XML. I like to use the Ribbon Editor. With the Ribbon Editor it looks like this:

    And in the Add-In it looks then like this:

    The CustomUI XML relevant part looks like this

    <group id="TD_GrpMisc" label="Misc">            
            <gallery 
                idMso="SlideNewGallery"
                size="large"/>
            <button 
                idMso="SlideNew"
                size="large"/>
    </group >
    
    0 讨论(0)
  • 2021-01-27 18:27

    i currently have new slide button in my addin like the image below which gives me a new slideenter image description here

    however I want the option like the already existing new slide in home ribbon where I can choose templates.Is there any way to invoke this button in my customized ribbon so below is my newslide that is what i want to get in my addin

    enter image description here

      private void New_slide_Click(object sender, RibbonControlEventArgs e)
        {
    
            PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
            ppApp.CommandBars.ExecuteMso("SlideNewGallery");
        }
    
    0 讨论(0)
  • 2021-01-27 18:28

    You can add built-in controls to your custom tab by soecifying their IdMso values. See Office 2013 Help Files: Office Fluent User Interface Control Identifiers .

    You can read more about the Ribbon UI in the following series of articles in MSDN:

    • Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
    • Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
    • Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
    0 讨论(0)
  • 2021-01-27 18:28

    I think after a lot of searching I finally figured it out! This is all the code you need, delete everything else This will create a new slide button just like the one that comes default in PowerPoint

    <group id="add_slide" label="Add Slide">
      <control idMso="SlideNewGallery" size="large" />
    </group>
    

    credit

    0 讨论(0)
提交回复
热议问题