how to set the (Apply to This point forward) when we chnage from page setup from portrait to lanscape or viice versa RRS feed

  • Question

  • hi every1,

    i hve a problem, big 1

    using word 2002, VSTO 2010, c#

    in word if u hve different sections, lets says 4 n u r in the 2nd section. u nw want to change z page orientation to landscape for this section n the remaining sections

    in word u hve smething called "This point forward" in z margin tab of the page setup window (which does it)

    does sme1 hve any idea how we do zis in coding plz???

    any help would b really appreciated :)



    Friday, January 7, 2011 11:11 AM

All replies

  • Hi Mush

    No, there's no equivalent to this in the object model. Your code would need to change the orientation for the current and then any following sections.

    Cindy Meister, VSTO/Word MVP
    Friday, January 7, 2011 11:44 AM
  • hi cindy,

    thks 4 ur quick reply

    i did wat u said, but getting a bug

    if u hve a section bbreak continous (meaning 2 section on same page) after ur current section, when u change to landscape zat same page split in two

    n if i do it in word wiz z this point forward things both section remain on same page but nw in landscape

    why does it not show same behaviour as the this point forward does???

    any idea???

    Friday, January 7, 2011 12:11 PM
  • Hi Mush

    <<n if i do it in word wiz z this point forward things both section remain on same page but nw in landscape>>

    Trying to read your abbreviated version of English is becoming very trying - the more you ask it seems the more you dare to abbreviate. At this point, I'm not sure I'm even understanding everything you write...

    In any case: The Word UI is helping the user to accomplish complex things. Such assistance is usually NOT included in the object model as it is possible for the developer to replicate the UI assistance if that's the effect he wants.

    This usually means a LOT more work for the developer, but that's the way it is...

    Of course, when one section is set to landscape and another to portrait, even if it's a continuous section break the other section will have to be on a new page until the property is changed for that section so that the page orientation coincides.

    You're just going to have to work it out until you get it the way you want it.

    And if you want a comment on your code, you're going to have to provide the code...

    Cindy Meister, VSTO/Word MVP
    Friday, January 7, 2011 12:31 PM
  • hi Cindy,

    sry for the abbreviated parts

    here is z code :


                int oStart = app.Selection.Range.Start;
                int oEnd = app.Selection.Range.End;
                Range oRng = app.Selection.Range;
                string pageOrientation = "";

                app.Selection.GoTo(Word.WdGoToItem.wdGoToLine, Word.WdGoToDirection.wdGoToLast, Type.Missing, Type.Missing);

                oEnd = app.Selection.Range.End;
                oRng = app.ActiveDocument.Range(oStart, oEnd);

                app.Selection.Start = oStart;

                if (app.Selection.Sections.PageSetup.Orientation == WdOrientation.wdOrientPortrait)
                    pageOrientation = "landscape";
                    pageOrientation = "portrait";

                int secCount = 1;
                while (secCount <= oRng.Sections.Count)
                    switch (pageOrientation)
                        case "landscape":
                            app.Selection.Sections.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
                        case "portrait":
                            app.Selection.Sections.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
                foreach (Table t in oRng.Tables)

    what it does is that from the point where my cursor is it add a section break. then changes the orientation from portrait to landscape and vice versa of this particular section, and the rest of the sections after that till end of doc




    Friday, January 7, 2011 12:47 PM