none
Apply shading to a table row RRS feed

  • Question

  • Hullo Awesome Cindy Meister,

    I was requested again by the IT Senior Team Leader regarding the WORD 2003 Table Column Header to set the Background color to GREY.  Please share with me the coding for it.

    Thank you.


    Thank you very Much, Have a Good Day. Cheers, Lennie
    • Split by Cindy Meister MVPModerator Monday, January 3, 2011 9:28 AM new question. Split for better visibility from http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/7f45f44a-0eab-4516-85ba-be7e31345898
    • Moved by Cindy Meister MVPModerator Monday, January 3, 2011 9:28 AM Word question (From:Visual Studio Tools for Office)
    Sunday, January 2, 2011 11:21 PM

Answers

  • Hi Cindy Meister,

    In my desperation for the past 48 hours and I have tried different technic and logic to test it and finally I got this coding and it's working

    This apply to the 1st Row and column Header text

    objTable.Rows[1].Shading.BackgroundPatternColor = Word.

    WdColor.wdColorGray; // BackGround Colour

    And this apply to the data row in the FOR LOOP logic to insert data onto the rows after the First Row.

    objTable.Rows[1].Shading.BackgroundPatternColor = Word.

    WdColor.wdColorWhite; // BackGround Colour


    Thank you very Much, Have a Good Day. Cheers, Lennie
    Monday, January 3, 2011 11:21 AM

All replies

  • Hi Lennie

    (VS 2008, C#, Word 2003)

    I've split this off into a new thread to make it easier to follow and more visible to those who could help you.

    I think it would be a good idea for us to show you how to get the basic syntax for what things you want to do in the Word object model, rather than you having to ask for every new step :-)

    Start Word as an end-user. Insert a table and select a row. Click on the Developer tab in the Ribbon, then on the button "Record macro". Give the macro a name, then click OK. Now apply the grey shading you want to use for the table. To stop the macro recorder after applying the shading, click "Stop recording".

    Now press Alt+F11 to open Word's VBA Editor. Look for the Project window (top-left) and in ope the Normal/Modules tree. You should see an entry NewMacros: double-click it to open the code window. Your recorded macro will be the last "Sub". Copy it to your reply and we'll explain how to "translate" that to C#. 

    Please also include a "stub" of your C# code that includes the Table.Row object you need to work with, so that we can put the sample into a meaningful context for you.


    Cindy Meister, VSTO/Word MVP
    Monday, January 3, 2011 9:38 AM
    Moderator
  • Hi Cindy Meister,

    In my desperation for the past 48 hours and I have tried different technic and logic to test it and finally I got this coding and it's working

    This apply to the 1st Row and column Header text

    objTable.Rows[1].Shading.BackgroundPatternColor = Word.

    WdColor.wdColorGray; // BackGround Colour

    And this apply to the data row in the FOR LOOP logic to insert data onto the rows after the First Row.

    objTable.Rows[1].Shading.BackgroundPatternColor = Word.

    WdColor.wdColorWhite; // BackGround Colour


    Thank you very Much, Have a Good Day. Cheers, Lennie
    Monday, January 3, 2011 11:21 AM