Check if Document is in Compatibility Mode using c# RRS feed

  • Question

  • Hi,

    I need to check if a doc is opened in Compatibility Mode in order to know if the button "File->Info->Convert" exists.

    Is it possible? I need it for word, excel and power-point.  The version of office is 2013.

    Another question: is it possible to press the button ("File->Info->Protect document") from the code?


    Thursday, September 3, 2015 8:41 AM

All replies

  • Hello,

    I believe you can use the Hwnd property of the Windows class to get the window handle and then use Windows API functions to get the caption with compatibility keywords. See GetWindowText which allows to get the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied.

    > is it possible to press the button ("File->Info->Protect document") from the code?

    Try to use CommandBars.Execute method which allows to run controls programmatically. You just need to pass the idMso value of the built-in control.

    Thursday, September 3, 2015 1:05 PM
  • Hi Shenhavba

    You can check whether the command is visible using:


    Returns True if it is; False if it's not.

    CommandBars belongs to the Word.Application object, in case you're not working in VBA.

    I don't think you can open the menu "Protect document" from code as that's not an individual command. The options IN that menu are available and can be executed. Is there any one, in particular, that you want to use?

    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, September 3, 2015 4:36 PM
  • Hi,

    I need to click the "connect to rights management server" button under "restrict access" button.

    I managed to to it with UI Automation but it may not work if the order of the buttons will be different.

    I need it to work for all languages.

    How can i do it with CommandBars? I am working with c# but a VBA example will be good too.


    Friday, September 4, 2015 4:54 AM
  • HI shenhavba

    OK, I don't have access to such a server, so that button is not available for me to test, however...

    If you go into File/OPtions/Customize Ribbon and from the left choose the "File" tab you should see a list of commands. One of them is, for example, "Restrict permission", which may be the "Restrict access" button you mention. You can Add that to a custom group in the Ribbon (or customize the QAT instead of the Ribbon and add it to that) then see if clicking that button opens what you need.

    If that's not it, try the same procedure for other commands that look like they might be what you're looking for (you might also recognize the icon).

    Once you find it, in the "Customize" dialog box hover the mouse pointer over that command name. After a short wait you should get a "flag" next to the mouse pointer. The text in (parentheses) is the idMso command name to use with ExecuteMso.

    If the command doesn't show up in the list for the "File" tab, try the category "All commands". I see, for example, one simply called "Permission".

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, September 4, 2015 2:08 PM
  • Hi,

    Thank you for your help, but the button i need is not in the list(when i press it and connect to the server, this button disappear and i get the Restricted permission and unrestrict buttons)

    Is there a way to press a button of type menu like the permission button and then get a list of the child buttons?


    Friday, September 4, 2015 3:54 PM
  • HI shenhavba

    The only way to "press" a Ribbon control is to use the Alt+keycommand combination Word assigns to the control (SendKeys). Problem with this is that you cannot rely on the key combination always being the same, depending on what add-ins with Ribbon customizations load. Word will change the combination at run time assigned key combinations conflict.

    At the top of the General Offiice dev forum are two pinned messages with links to information about customizing the Ribbon. One of these is a file you can download with all the Ribbon customization commands (idMso). Perhaps you can turn it up in that...

    Or, if the button you want to "click" brings up a dialog box you might find that dialog box in the object model, as part of the WdDialog enumeration. If it's there, then you can use the .Show method to display it.

    Cindy Meister, VSTO/Word MVP, my blog

    Monday, September 7, 2015 3:33 PM