none
How to Open a UserControl from a Word Add-In RRS feed

  • Question

  • All,

    I have a Word Add-In that adds a new Tab on the Ribbon.  The tab only has one group, with one button.  I'd like to open a usercontrol when the button is clicked.  Could someone point me in the direction of how to accomplish this?

    Thursday, February 2, 2012 3:32 PM

Answers

  • I solved my ALL my issues.  What one have to do if you're developing an add-in for Office 2010.  Ignore all the videos out there that and watch this one first: http://www.i8dm.com/media/Ribbon_Customisation_Moth.wmv
    • Marked as answer by Kevon Hayes Thursday, February 2, 2012 7:52 PM
    Thursday, February 2, 2012 7:52 PM

All replies

  • Hi Kevon

    Is this a VSTO add-in or an IDTextensibility2 Add-in ("Shared Add-in")?

    Can you be more specific about what you mean by a "usercontrol"? Do you mean a Windows Form? Or a Custom Task Pane? Something else?

    Which version of Word is involved and which programming language?


    Cindy Meister, VSTO/Word MVP
    Thursday, February 2, 2012 4:59 PM
    Moderator
  • I really mean a Windows Form.  I'm a web developer and haven't done any Office Development Ever.  I'm trying to get add a new Tab on the Ribbon, I've done that via the XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns" label="FOIA">
            <group id="COR" label="JUSTIFICATIONS" visible="true" >
                <button size="large" imageMso="AccessNavigationOptions"   onAction="MyButtonOnAction" description="Click to display complete list of Justifications." enabled="true"  />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    


    but my custom image doesn't show up and I my form doesn't open either

     

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Core;
    using System.Windows;
    using System.Windows.Forms;
    // TODO:  Follow these steps to enable the Ribbon (XML) item:
    
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    
    //  protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    //  {
    //      return new FOIA();
    //  }
    
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    //    actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    //    move your code from the event handlers to the callback methods and modify the code to work with the
    //    Ribbon extensibility (RibbonX) programming model.
    
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.  
    
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    
    
    namespace FOIAResponses
    {
        [ComVisible(true)]
        public class FOIA : Office.IRibbonExtensibility
        {
            private Office.IRibbonUI ribbon;
    
            public FOIA()
            {
            }
    
            #region IRibbonExtensibility Members
    
            public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("FOIAResponses.FOIA.xml");
            }
    
            #endregion
    
            #region Ribbon Callbacks
            //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    
            public void MyButtonOnAction(IRibbonControl control)
            {
                object objForm = Activator.CreateInstance(Type.GetType("FOIAResponses.JustificationForm"));
                Form justificationForm = (Form)objForm;
                justificationForm.Show();
            }
    
            #endregion
    
            #region Helpers
    
            private static string GetResourceText(string resourceName)
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] resourceNames = asm.GetManifestResourceNames();
                for (int i = 0; i < resourceNames.Length; ++i)
                {
                    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                        {
                            if (resourceReader != null)
                            {
                                return resourceReader.ReadToEnd();
                            }
                        }
                    }
                }
                return null;
            }
    
            #endregion
        }
    }
    


    Thursday, February 2, 2012 5:20 PM
  • I solved my ALL my issues.  What one have to do if you're developing an add-in for Office 2010.  Ignore all the videos out there that and watch this one first: http://www.i8dm.com/media/Ribbon_Customisation_Moth.wmv
    • Marked as answer by Kevon Hayes Thursday, February 2, 2012 7:52 PM
    Thursday, February 2, 2012 7:52 PM