none
Preserve macro button border after applying format painter (Word 2010) RRS feed

  • Question

  • I have the following code which inserts a macro button field into the word document:

    using WordNS = Microsoft.Office.Interop.Word;
    
    WordNS.Field field = _application.ActiveDocument.Fields.Add(currentRange,WordNS.WdFieldType.wdFieldMacroButton, "macro button field",false);
    field.Locked = true;
    field.Code.Borders.Enable = 1;

    Users are allowed to modify properties such as font family,size,background colours and so on.But I would like the macro button to stand out from the rest of the text by having a permanent border around it.

    At the moment if I apply Format Painter to the macro button field the border is removed:

    Format Painter in MS Word

    Question:

    1) Is there any way to prevent this from happening? or

    2) Is there a way to detect that the macro button field border has been removed and re-apply it somehow?

    Tags:

    MS Office Word 2010

    C#

    VSTO 4.0


    • Edited by Denys W Tuesday, October 16, 2012 1:30 PM
    Tuesday, October 16, 2012 1:30 PM

Answers

  • Hi Denys

    There's no way to prevent the change from happening.

    I can't think of any really good, simple way to detect that the border has been removed except for looping all the field codes in the document, checking whether they're of type wdFieldMacrobutton and, if they are, to apply the formatting, as Leo suggests.

    However, a macro button field will not be a member of the InlineShapes collection. The Field.Result property should return a Range, so you'd want to apply the Border to that.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 17, 2012 2:45 PM
    Moderator

All replies

  • Hi Denys,

    Thanks for posting in the MSDN Forum.

    It's based on my knowledge you can try to add this

    field.InlineShape.Borders.Enable = True;

    Hope it helps.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 8:59 AM
    Moderator
  • Hi Denys

    There's no way to prevent the change from happening.

    I can't think of any really good, simple way to detect that the border has been removed except for looping all the field codes in the document, checking whether they're of type wdFieldMacrobutton and, if they are, to apply the formatting, as Leo suggests.

    However, a macro button field will not be a member of the InlineShapes collection. The Field.Result property should return a Range, so you'd want to apply the Border to that.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 17, 2012 2:45 PM
    Moderator