none
c# .net 4and word interop dll RRS feed

  • Question

  • Hi,

    So sorry if i am posting in the wrong forum. 

    I need help with adding a tab stop(position at 1cm) to a word document using word interop and c#. This is what i tried already.

    Range range = paragraph.Range;
    int firstTabStart = range .Start;
    range .SetRange(firstTabStart, firstTabStart);
    range .Paragraphs.TabStops.Add(5, WdTabAlignment.wdAlignTabRight);

    When i open my word document i dont see any tab stops. I can however insert tab alignments using

    range .InsertAlignmentTab((int)WdAlignmentTabAlignment.wdCenter,
        (int)WdAlignmentTabRelative.wdMargin);

    Although, these tabs are absolute and I cannot give a measurement alignment or edit them i word 2010 when inserted.

    Please help.

    Wednesday, May 22, 2013 10:30 AM

All replies

  • Can you manually add tab for that range?

    I am not sure if the range is invalid for adding tab, just a guess.

    Friday, May 24, 2013 4:27 AM
  • Hi stylo

    The first argument of the TabStops.Add method sets the position, in points:

    "The position of the tab stop (in points) relative to the left margin."

    5 Points is a fairly small measurement. Are you sure the tab stop isn't there? If you look in the Tabs dialog box, is it listed? (If you don't know how to open the Tabs dialog box in the Word UI, please tell us the version of Word you're using.)

    The other issue might be your use of Range.Paragraphs.TabStops.Add. Since you appear to want to affect a single paragraph, only, why not use: range.Paragraphs[1].TabStops.Add ?


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, June 2, 2013 11:20 AM
    Moderator