Ask a questionAsk a question
 

AnswerCustomize Outlook 2007 Command Bar

  • Thursday, November 05, 2009 8:54 PMWizKid730 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have developed a Outlook Add-In for my company. I need to insure that the Command Bar always shows up in the same place on startup. I want it on the far right next to the Standard Command Bar. How do I figure out that location?

    Also, it was requested that the Command Bar be a separate background color to match company standard. Is it possible to mofify that property, if so, how?
    Not really a kid and not really a wizard

Answers

  • Thursday, November 12, 2009 5:42 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello,

    <<I want it on the far right next to the Standard Command Bar.>>
    To set a custom command bar next to the Standard Command Bar, we need to set the RowIndex and Left property of a command bar [See: CommandBar Object Members]. When creating a command bar by using Add method and setting visible property to True, the RowIndex of this command bar is set to 5 by default, and the Left property is set to 0. If we do not change these values, this command bar is under the Standard command bar. So we need to change these property value. For test, in my said, I have made a test. Code like this,

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {       
                Office.CommandBar myCommandBar;
                Office.CommandBarComboBox ComboBox1;
                Office.CommandBarComboBox ComboBox2;

                Office.CommandBar comb = this.Application.ActiveExplorer().CommandBars["Standard"];
                //Debug.Print("RowIndex=" + comb.RowIndex.ToString() + " Left=" + comb.Left.ToString() + " Height =" + comb.Height.ToString());
                myCommandBar = this.Application.ActiveExplorer().CommandBars.Add("custom", Office.MsoBarPosition.msoBarTop, false, true);
                //Debug.Print("RowIndex=" + myCommandBar.RowIndex.ToString() + " Left=" + myCommandBar.Left.ToString() + " Height =" + myCommandBar.Height.ToString());     
                myCommandBar.Visible = true;
                Debug.Print("RowIndex=" + myCommandBar.RowIndex.ToString() + " Left=" + myCommandBar.Left.ToString() + " Height =" + myCommandBar.Height.ToString());

                myCommandBar.RowIndex=comb.RowIndex;
                myCommandBar.Left = 100;   
                ......                 
           }

    By loading this add-in in Outlook, you will see this command bar next to Standard command bar.

    Here is another way to achieve this, or save the position of a custom command bar after changing in Outlook. For example, we change a custom command bar position by dragging it. If want to see this custom command bar in new position next time,  here we need to write code to this add-in.  For this, you could refer to these resources:
    How to: Maintain Position Information for Custom Toolbars between Outlook Sessions.
    Error saving command bar position: Outlook 2007, VS 2008 add-in.

    For background color of a command bar, unfortunately, Outlook object model does not expose such a property/method to modify it.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Thursday, November 12, 2009 5:42 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello,

    <<I want it on the far right next to the Standard Command Bar.>>
    To set a custom command bar next to the Standard Command Bar, we need to set the RowIndex and Left property of a command bar [See: CommandBar Object Members]. When creating a command bar by using Add method and setting visible property to True, the RowIndex of this command bar is set to 5 by default, and the Left property is set to 0. If we do not change these values, this command bar is under the Standard command bar. So we need to change these property value. For test, in my said, I have made a test. Code like this,

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {       
                Office.CommandBar myCommandBar;
                Office.CommandBarComboBox ComboBox1;
                Office.CommandBarComboBox ComboBox2;

                Office.CommandBar comb = this.Application.ActiveExplorer().CommandBars["Standard"];
                //Debug.Print("RowIndex=" + comb.RowIndex.ToString() + " Left=" + comb.Left.ToString() + " Height =" + comb.Height.ToString());
                myCommandBar = this.Application.ActiveExplorer().CommandBars.Add("custom", Office.MsoBarPosition.msoBarTop, false, true);
                //Debug.Print("RowIndex=" + myCommandBar.RowIndex.ToString() + " Left=" + myCommandBar.Left.ToString() + " Height =" + myCommandBar.Height.ToString());     
                myCommandBar.Visible = true;
                Debug.Print("RowIndex=" + myCommandBar.RowIndex.ToString() + " Left=" + myCommandBar.Left.ToString() + " Height =" + myCommandBar.Height.ToString());

                myCommandBar.RowIndex=comb.RowIndex;
                myCommandBar.Left = 100;   
                ......                 
           }

    By loading this add-in in Outlook, you will see this command bar next to Standard command bar.

    Here is another way to achieve this, or save the position of a custom command bar after changing in Outlook. For example, we change a custom command bar position by dragging it. If want to see this custom command bar in new position next time,  here we need to write code to this add-in.  For this, you could refer to these resources:
    How to: Maintain Position Information for Custom Toolbars between Outlook Sessions.
    Error saving command bar position: Outlook 2007, VS 2008 add-in.

    For background color of a command bar, unfortunately, Outlook object model does not expose such a property/method to modify it.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.