How to hide "Apply XML-element" menu point in the right click contextmenu ? RRS feed

  • Question

  • Hello,

    We have developed a addIn for Word 2010.

    I wanted to know if there is any possibility (programmatically) to not show the context menu item "ApplyXML-element", that is when right clicking on a text.

    This menu item appears when we open an xml document file in word.

    I have looked in the WordControls.xlsx excel sheet for the control name but could't find it.

    Thanks for your help.




    Thursday, January 12, 2012 11:32 AM

All replies

  • Hi Henrik

    I don't see this if I open a "plain" XML document, only if I open one been developed in, for example, Word 2003 that's had a schema linked to it.

    Since this technology has essentially been removed in Word 2010 I guess I'm not surprised that there's no idMso publicized for it. The way to get the menu entry to disappear is to remove the link to the schema library from the document.

    Cindy Meister, VSTO/Word MVP
    • Marked as answer by HenrikPedersen Friday, January 13, 2012 12:35 PM
    • Unmarked as answer by HenrikPedersen Thursday, February 23, 2012 12:29 PM
    Thursday, January 12, 2012 4:34 PM
  • Hi Cindy,

    thanks for the reply. :)

    Yes, our xml document have a schema linked to it and has been developed in Word2003.

    I will try to see if we can remove the link to the schema library.


    Friday, January 13, 2012 9:07 AM
  • Hi Cindy,

    we need the link to the schema library for our document, so I guess we can't get rid of this menu point.



    Friday, January 13, 2012 12:35 PM
  • Hi Cindy,

    We have made a custom wordML editor using a Word Document Level Customization. We have attached our own schemas to the document. It is critical to our customer that we hide the "Apply XML", and the "Attributes:" menu items from the context menu.

    We have also tried to look for the idMso for this menu item, in order to disable the command in Ribbon xml but haven't found it.

    Do you know of another way to hide this. Maybe through registry key settings in the HKEY_CURRENT_USER\Software\Policies\Microsoft\office\14.0\Word\DisabledCmdBarItemsList hive ?

    Like they do with other Right Click items in

    But i dont no how to get hold of the TCIDs to add to the registry (if one exists).

    Thursday, February 23, 2012 12:27 PM
  • Hello,

    If that control is a CommandBar control then it probaly shows up only in a specific environment; I can't find it in my Word 2010.

    Below is an Excel macro that print Word's CommandBar controls' names and IDs onto the active sheet. Before you run the code, you must start Word, open a document and select the area that produces the control in question when right-clicked; right-click it - this may be required for Word to create that control.

    Also, I wrote this for Word 2007-2010; otherwise, you need to modify the code because the output takes more than 255 columns.

    When the code completes, you search through the Excel sheet for that control. If it exists, then the comment for that cell contains the ID of that control.

    Private Sub GetWordControls()
    Dim WordApp As Word.Application
    Set WordApp = GetObject(, "Word.Application")
    Dim cBars As Office.CommandBars
    Set cBars = WordApp.CommandBars
    Dim iBars As Integer
    Dim j As Integer
    j = 1
    Dim iRow As Integer, iCol As Integer
    iRow = 1
    iCol = 1
    Dim r As Excel.Range
    For iBars = 1 To cBars.Count
        Dim cb As Office.CommandBar
        Set cb = cBars(iBars)
        Set r = ActiveSheet.Cells(iRow, iCol)
        r.Value = cb.Name
        Dim ctrls As Office.CommandBarControls
        Set ctrls = cb.Controls
        iRow = iRow + 1
        Call PrintControls(ctrls, iRow, iCol)
        iRow = iRow + 1
        iCol = 1
    Next iBars
    End Sub
    Private Sub PrintControls(ctrls As Office.CommandBarControls, ByRef iRow As Integer, ByRef iCol As Integer)
    Dim i As Integer
        If ctrls.Count = 0 Then
            ActiveSheet.Cells(iRow, iCol).Value = "{No controls}"
            For i = 1 To ctrls.Count
                iCol = iCol + 1
                Dim str As String
                str = RemoveApms(ctrls(i).Caption)
                ActiveSheet.Cells(iRow, iCol).Value = str
                Dim rr As Excel.Range
                Set rr = ActiveSheet.Cells(iRow, iCol)
                rr.AddComment CStr(ctrls(i).ID)
                If TypeOf ctrls(i) Is Office.CommandBarPopup Then
                    iRow = iRow + 1
                    Call PrintControls(ctrls(i).Controls, iRow, iCol)
                End If
            Next i
        End If
    End Sub
    Private Function RemoveApms(str As String) As String
        RemoveApms = VBA.Replace(str, "&", "")
        If str = "" Then str = "{Empty}"
    End Function

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Thursday, February 23, 2012 1:57 PM