none
embed word document in C# winforms, Have to disable/hide Quick access toolbar. RRS feed

  • Question

  • Hi Team,

    Currently i am embedding a word document in winforms. I need to disble/hide/remove the quick access toolbar from the word, i was tried in different ways like below ways in C#  but it's not working .

    With oDocument.Application.CommandBars("Standard")'disable the standard toolbar
          .Enabled = False
          .Visible = False
     End With

    WebBrowser1.ExecWB OLECMDID_HIDETOOLBARS, OLECMDEXECOPT_DONTPROMPTUSER'toggle between "reviewing" and "standard" toolbar
    End Sub

    Any help would be highly appreciate.Thanks.

    Monday, February 16, 2015 12:03 PM

Answers

  • Hi Ravindra

    The code you're trying to use is for the old "toolbar" GUI that was discontinued in the Office applications starting with version 2007. CommandBars is still present in the object model and does interact with the new "Ribbon" interface to a certain extent, but it's NOT used to affect visibility.

    The Ribbon GUI, introduced in Office 2007, is defined by "Ribbon XML" and cannot be affected by code running from outside the application interface, nor by code running in-process that's not part of the same "container" as defines the Ribbon XML.

    From the screen shot you provide, it looks like you want to work with a specific type of document ("Custom Letter")? If yes, then it would be best for you to create a template that contains the Ribbon definition you want to provide for that type of document. In order to suppress the QAT you need to use the "startFromScratch" command for the customUI which also means that the Ribbon XML must define the ENTIRE Ribbon interface you want to provide to your users.

    You'll find the basics about customizing the Ribbon in the three-part article "for developers". You can find links to that, as well as to other information concerning the Ribbon,here: https://social.msdn.microsoft.com/Forums/office/en-US/ba8c9d0b-7312-4503-8167-f2ef86f17435/information-on-the-office-fluent-ui-ribbon-for-developers?forum=officegeneral


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 16, 2015 12:25 PM
    Moderator
  • Hi Ravindra

    Ribbon XML is never "available" to your code running outside of Word. But there is no other API you can use to affect the Ribbon or the QAT. This was a specific design decision made by Microsoft. Also, the Office applications are specifically designed to be USER tools, not developer tools. Microsoft has deliberately made it "uncomfortable" to embed an Office application in another "container" and what you can do to customize the application is limited.

    You basically have two approaches:

    1. Create a IDT2Extensibility Add-in in order to define the Ribbon XML for the entire application. Your code should be able to load/unload the add-in "on-demand" (rather than allowing Word to load it automatically, when it starts)

    2. Create a template and link any document you open or create to it (set the AttachedTemplate property) so that the Ribbon XML in the template takes precedence over Word's default Ribbon settings.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 16, 2015 8:29 PM
    Moderator

All replies

  • Hi Ravindra

    The code you're trying to use is for the old "toolbar" GUI that was discontinued in the Office applications starting with version 2007. CommandBars is still present in the object model and does interact with the new "Ribbon" interface to a certain extent, but it's NOT used to affect visibility.

    The Ribbon GUI, introduced in Office 2007, is defined by "Ribbon XML" and cannot be affected by code running from outside the application interface, nor by code running in-process that's not part of the same "container" as defines the Ribbon XML.

    From the screen shot you provide, it looks like you want to work with a specific type of document ("Custom Letter")? If yes, then it would be best for you to create a template that contains the Ribbon definition you want to provide for that type of document. In order to suppress the QAT you need to use the "startFromScratch" command for the customUI which also means that the Ribbon XML must define the ENTIRE Ribbon interface you want to provide to your users.

    You'll find the basics about customizing the Ribbon in the three-part article "for developers". You can find links to that, as well as to other information concerning the Ribbon,here: https://social.msdn.microsoft.com/Forums/office/en-US/ba8c9d0b-7312-4503-8167-f2ef86f17435/information-on-the-office-fluent-ui-ribbon-for-developers?forum=officegeneral


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 16, 2015 12:25 PM
    Moderator
  • Thanks Cindy,

     I was hosted a word document in webbrowser control so i think RibbonXML won't be available at this point of time if i am not wrong. The title custom letter says it's just hosting a document in webbrowser. so i can i disable Quick access toolbar from document in webbrowser control.

    Thanks  

    Monday, February 16, 2015 1:22 PM
  • Hi Ravindra

    Ribbon XML is never "available" to your code running outside of Word. But there is no other API you can use to affect the Ribbon or the QAT. This was a specific design decision made by Microsoft. Also, the Office applications are specifically designed to be USER tools, not developer tools. Microsoft has deliberately made it "uncomfortable" to embed an Office application in another "container" and what you can do to customize the application is limited.

    You basically have two approaches:

    1. Create a IDT2Extensibility Add-in in order to define the Ribbon XML for the entire application. Your code should be able to load/unload the add-in "on-demand" (rather than allowing Word to load it automatically, when it starts)

    2. Create a template and link any document you open or create to it (set the AttachedTemplate property) so that the Ribbon XML in the template takes precedence over Word's default Ribbon settings.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 16, 2015 8:29 PM
    Moderator