Table content auto fit to Window RRS feed

  • Question

  • Hi,

    I am not able to set the content of table to autofit to windo by using following code snippet.

    foreach (Word.Table table in this.wordDoc.Tables)
                        table.Rows.SetLeftIndent(0, WdRulerStyle.wdAdjustNone);
                        table.Rows.LeftIndent = 0;

    Please note that while I have set defaultAutoFit to Word.WdDefaultTableBehavior.wdWord8TableBehavior. Will it have any impact on AutofFirBehavior method. Please advise.



    Wednesday, May 11, 2011 10:48 AM


  • Hi,


    Why don’t you record a macro in Word UI to see how the action performs in VBA and code it in VSTO?


    Please see the VBA code:


      Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)

    Then you can code this action via C#:

                Word.Application app = this.Application;

                Word.Document doc = app.ActiveDocument;           

                foreach (Word.Table table in doc.Tables)





    The code above works fine on my side.


    I hope this helps.

    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Calvin_Gao Tuesday, May 17, 2011 1:55 PM
    Monday, May 16, 2011 12:04 PM