none
ContentControl using Word.Editor allows no formatting on the first and last paragraph RRS feed

  • Question

  • We have a Word addin which uses ContentControl's to allow locking various section of the document. We add a Word.Editor to the control.  The problem is that if you select text in the first or last paragraph, the paragraph formatting buttons disable, such as Left-Align, Centered, etc. Selecting in any other paragraphs these buttons are enabled.

    I have validated that the range specified for the selected text is within the range of the content control as well as the range for the Word.Editor.

    Wednesday, August 27, 2014 8:44 PM

Answers

  • Hi rschluet,

    >> I don't think this could be by design.

    Yes, you are correct, it is not by design. Please ignore Fei Xue’s suspicion and sorry for the confusing.

    Based on my understanding, it is because the contentControl.Range does not include the begin character and end character. When restricting a content control, we need to select the whole content control rather than selecting all the text in it.

    In VBA or VSTO, we may need to use the code below to work around it:

    Sub AddEditorToContentControlRange()
        Dim contentControl As contentControl
        Dim startPos As Integer
        Dim endPos As Integer
        Set contentControl = Application.ActiveDocument.ContentControls(2)
        startPos = contentControl.Range.start - 1
        endPos = contentControl.Range.End + 1
        Application.ActiveDocument.Range(startPos, endPos).Editors.Add WdEditorType.wdEditorEveryone
    End Sub

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 2, 2014 2:26 AM
    Moderator

All replies

  • Hi rschluet,

    Thanks for posting on MSDN forum.

    >>We have a Word addin which uses ContentControl's to allow locking various section of the document. We add a Word.Editor to the control.  The problem is that if you select text in the first or last paragraph, the paragraph formatting buttons disable, such as Left-Align, Centered, etc. Selecting in any other paragraphs these buttons are enabled. <<

    Which type of content control are you using and what's mean of 'Word.Editor'? Does these buttons works when you insert the content control and 'Word.Editor' manually?

    I created a Rich Text Content Control and typed three paragraphs, and the buttons you metioned above works well for me.

    Did I miss any stpes? Would you mind providing some code snippet to help us to reproduce this issue?

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 28, 2014 3:26 AM
    Moderator
  • Hi Fei Xue

    By "Word.Editor" the OP means the "Exceptions" part of "Read Only" set in the "Restrict Editing" taskpane. See, for example: http://msdn.microsoft.com/en-us/library/office/ff836293(v=office.15).aspx


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, August 28, 2014 4:24 PM
    Moderator
  •  cc = this.theDocument.ContentControls.Add(WdContentControlType.wdContentControlRichText, rangeCopy);

     controlEditor = control.Range.Editors.Add(Word.WdEditorType.wdEditorEveryone);

    This is the code which creates the content control and the editor.

    Here is an interesting fact:

    After the cc is created, the cc.Range.Start is 1 larger than rangeCopy.Start

    and cc.Range.End is 2 less than rangeCopy.End

       

     
    Thursday, August 28, 2014 4:45 PM
  • Also, I tried moving the Start and End of the control.Range using:

                 control.Range.MoveStart(WdUnits.wdCharacter, -1);
                 control.Range.MoveEnd(WdUnits.wdCharacter, 2);

    But this has no effect on the control.Range Start and End.

    Thursday, August 28, 2014 5:01 PM
  • Hi All,

    First, thanks Cindy for your detail information about the Editor.

    >>The problem is that if you select text in the first or last paragraph, the paragraph formatting buttons disable, such as Left-Align, Centered, etc. Selecting in any other paragraphs these buttons are enabled<<

    @Rschluet, the issue could be reproduced even we add the 'Restrict Editing' manually. So I suspect this is by designed, however I couldn't find the document describing it.

    I suggest that you submit the feedback from link below if you want this feature to supprt formating the first and last paragraph:
    Submit Feedback

    Best regards

    Fei 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 29, 2014 9:52 AM
    Moderator
  • I don't think this could be by design.  You create a content control and assign editors to it so they can edit it.  Why would they exclude the first and last paragraph?

    Also, what about the strange behavior I noted above that the range of the content control does not match the range I passed in, nor can I modify it afterwards.

    Cindy, if you are still monitoring this, I would like your opinion.

    Thanks

    Friday, August 29, 2014 3:36 PM
  • Hi rschluet,

    >> I don't think this could be by design.

    Yes, you are correct, it is not by design. Please ignore Fei Xue’s suspicion and sorry for the confusing.

    Based on my understanding, it is because the contentControl.Range does not include the begin character and end character. When restricting a content control, we need to select the whole content control rather than selecting all the text in it.

    In VBA or VSTO, we may need to use the code below to work around it:

    Sub AddEditorToContentControlRange()
        Dim contentControl As contentControl
        Dim startPos As Integer
        Dim endPos As Integer
        Set contentControl = Application.ActiveDocument.ContentControls(2)
        startPos = contentControl.Range.start - 1
        endPos = contentControl.Range.End + 1
        Application.ActiveDocument.Range(startPos, endPos).Editors.Add WdEditorType.wdEditorEveryone
    End Sub

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 2, 2014 2:26 AM
    Moderator