none
Two question as Ribbon in word RRS feed

  • Question

  • Two question as Ribbon:
    1. How am I set my ribbon as default, when I open word, it open me in this ribbon instead of the standart?
    2. How am I add tooltip to the button in my ribbon?
    Wednesday, March 14, 2012 11:58 AM

Answers

  • Hila_d, I am afraid you may need to create an application level Add-In project to achieve the goal, because the document level ribbon customization via custom UI editor can't achieve the goal. Following are the steps to achieve the goal via application level Add-In:

    1. Create a Office 2010 application level Add-In, for example named WordAddInRibbonActivateTab

    2. Add an Ribbon(XML) Item to the project named Ribbon1.cs

    3. Paste the following xml text to the Ribbon1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
    
      <ribbon startFromScratch="false">
        <tabs>
          <tab id="myTab" label="My Custom Tab">
            <group id="customGroup" label="My Custom Group">
              <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    4. Add the ribbon variable and change the Ribbon_Load method in the Ribbon1.cs like this:

            public  Office.IRibbonUI ribbon;
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
                ribbon.ActivateTab("myTab");
            }

    5. Register the DocumentOpen event in the Startup method in ThisAddIn.cs, the full code in it looks like this:

    using Word = Microsoft.Office.Interop.Word;
    
    namespace WordAddInRibbonActivateTab
    {
        public partial class ThisAddIn
        {
            private Ribbon1 myCustomRibbon = null;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
            }
    
            void Application_DocumentOpen(Word.Document Doc)
            {
                myCustomRibbon.ribbon.ActivateTab("myTab");
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                myCustomRibbon = new Ribbon1();
                return myCustomRibbon;
            }
    
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }

    I am familiar with C# programming and it can also use VB.NET if you are familiar about it. 

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Bruce Song Tuesday, March 20, 2012 6:23 AM
    • Marked as answer by Bruce Song Monday, April 2, 2012 6:47 AM
    Tuesday, March 20, 2012 6:23 AM

All replies

  • 1) I'm afraid you cannot really focus to your ribbon. Apparently it's on purpose-, Microsoft didn't want programmers to be able to confuse users by having tabs change programmatically.

    2) Are you using Visual Studio? If you can, go to the ribbon design view, select the button/control, and in the properties window scroll down to the SuperTip property. SuperTip is pretty much the Tooltip.

    Wednesday, March 14, 2012 12:21 PM
  • 2. no, How am I add tooltip to the button in my ribbon?
    Wednesday, March 14, 2012 1:45 PM
  • If you are using XML to create your ribbon tab, place it before the Home tab. See Customize the Ribbon (It doesn't take rocket science) – Microsoft Word Help, Tips and Tutorials @ The Anchorage

    You add the tooltip as an attribute of the button control. Screentip and supertip are both available.

    You may want to look at RibbonX: Customizing the Office 2007 Ribbon- by Robert Martin, Ken Puls, and Theresa Hennig.

    Wednesday, March 14, 2012 2:28 PM
  • 1. I do that:

    Option Explicit
    Private WithEvents app As Application
    
    Private Sub app_DocumentOpen(ByVal Doc As Document)
        If Not rib Is Nothing Then
            rib.ActivateTab "myTab"
        End If
    End Sub
    
    Private Sub app_NewDocument(ByVal Doc As Document)
        
        If Not rib Is Nothing Then
            rib.ActivateTab "myTab"
        End If
    End Sub
    
    Private Sub Document_New()
        Set app = Application
        Call init
    End Sub
    
    Private Sub Document_Open()
        Set app = Application
        Call OnLoad
        Call init
    End Sub
    
    
    
    
    Public Sub OnLoad(ribbon As IRibbonUI)
        Set rib = ribbon
        tst = 1
        rib.ActivateTab "myTab"
    End Sub

    If I open New document, It open at my tab, but If I open document It open at home tab.

    what am I need to do?

    Sunday, March 18, 2012 1:43 PM
  • Hila_d, I tested the following code on my side and it works for me. When open the document, I can activate the myTab:

    Why did you write events for the open and new method? You don't have to write it, just write the OnLoad callback:

    Ribbon  Xml:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
    	<ribbon startFromScratch="false">
    		<tabs>
    			<tab id="myTab" label="Custom Tab">
    				<group id="customGroup" label="Custom Group">
    					<button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
    				</group>
    			</tab>
    		</tabs>
    	</ribbon>
    </customUI>

    vba code:

    Private WithEvents app As Application
    Public rib As IRibbonUI
    
    Private Sub app_DocumentOpen(ByVal Doc As Document)
    '    If Not rib Is Nothing Then
    '        rib.ActivateTab "myTab"
    '    End If
    End Sub
    
    Private Sub app_NewDocument(ByVal Doc As Document)
    '
    '    If Not rib Is Nothing Then
    '        rib.ActivateTab "myTab"
    '    End If
    End Sub
    
    Private Sub Document_New()
        Set app = Application
        'Call init
    End Sub
    
    Private Sub Document_Open()
        Set app = Application
       ' Call OnLoad(rib)
       ' Call init
    End Sub
    
    
    
    
    Public Sub OnLoad(ribbon As IRibbonUI)
        Set rib = ribbon
        tst = 1
        rib.ActivateTab "myTab"
    End Sub

    Hope this can help you and just feel free to follow up after you have tried.


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 19, 2012 6:57 AM
  • it work on I open new file, but If I click on file to open, It open him at tabHome.

    what it is?

    Monday, March 19, 2012 11:14 AM
  • Hila_d, I am afraid you may need to create an application level Add-In project to achieve the goal, because the document level ribbon customization via custom UI editor can't achieve the goal. Following are the steps to achieve the goal via application level Add-In:

    1. Create a Office 2010 application level Add-In, for example named WordAddInRibbonActivateTab

    2. Add an Ribbon(XML) Item to the project named Ribbon1.cs

    3. Paste the following xml text to the Ribbon1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
    
      <ribbon startFromScratch="false">
        <tabs>
          <tab id="myTab" label="My Custom Tab">
            <group id="customGroup" label="My Custom Group">
              <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    4. Add the ribbon variable and change the Ribbon_Load method in the Ribbon1.cs like this:

            public  Office.IRibbonUI ribbon;
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
                ribbon.ActivateTab("myTab");
            }

    5. Register the DocumentOpen event in the Startup method in ThisAddIn.cs, the full code in it looks like this:

    using Word = Microsoft.Office.Interop.Word;
    
    namespace WordAddInRibbonActivateTab
    {
        public partial class ThisAddIn
        {
            private Ribbon1 myCustomRibbon = null;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
            }
    
            void Application_DocumentOpen(Word.Document Doc)
            {
                myCustomRibbon.ribbon.ActivateTab("myTab");
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                myCustomRibbon = new Ribbon1();
                return myCustomRibbon;
            }
    
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }

    I am familiar with C# programming and it can also use VB.NET if you are familiar about it. 

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Bruce Song Tuesday, March 20, 2012 6:23 AM
    • Marked as answer by Bruce Song Monday, April 2, 2012 6:47 AM
    Tuesday, March 20, 2012 6:23 AM
  • how am I write it at VB?
    Tuesday, March 20, 2012 1:24 PM
  • Hila_d, below is the vb.net code snippet:

    Ribbon1.vb:

    Public ribbon As Office.IRibbonUI
    
    #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 Sub Ribbon_Load(ByVal ribbonUI As Office.IRibbonUI)
            Me.ribbon = ribbonUI
            ribbon.ActivateTab("myTab")
        End Sub
    #End Region

    ThisAddIn.vb:

    Imports Word = Microsoft.Office.Interop.Word
    Public Class ThisAddIn
    
        Private myCustomRibbon As Ribbon1
        ' Private WithEvents oWord As Word.Application
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            AddHandler Me.Application.DocumentOpen, AddressOf Application_DocumentOpen
    
        End Sub
    
    
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
    
        End Sub
    
    
        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            myCustomRibbon = New Ribbon1()
            Return myCustomRibbon
        End Function
    
    
        Private Sub Application_DocumentOpen(Doc As Word.Document)
            myCustomRibbon.ribbon.ActivateTab("myTab")
        End Sub
    
    End Class

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 21, 2012 10:05 AM