none
having problem to set only part of my doc to landscape n back to portrait RRS feed

  • Question

  • hi every1,

    using word 2002, visual studio 2010 c#

    i hve a problem, a big 1

    i need to set page from where my cursor is till end of document to landscape if it was portrait, suppose i hve 4 pages in my doc n my cursor is on 2nd page, wat i need to do is set orientation of page from where my cursor is till end of doc

    i tried this

     

    public void Portrait_Landscape_Click(CommandBarButton Ctrl, ref bool CancelDefault)
            {
                int oStart = app.Selection.Range.Start;
                int oEnd = app.Selection.Range.End;
                Range oRng = app.Selection.Range;

                object missing = Missing.Value;
                object what = Word.WdGoToItem.wdGoToLine;
                object which = Word.WdGoToDirection.wdGoToLast;
                app.Selection.GoTo(ref what, ref which, ref missing, ref missing);

                oEnd = app.Selection.Range.End;

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

                oRng.Select();
                app.Selection.Range.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
                //app.Selection.Range.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
               
            }

     

    but wiz z above code my whole document changes to landscape, (trying for portrait to landscape in z 1st place :) )

    where am i wrong??? plz help me correct it

    or plz suggest smething if zats nt z way to do it

    thks in advance

    Mush

    :)

    Wednesday, January 5, 2011 7:37 AM

Answers

  • Hi Mush,

    Your code is written to change the layout of the whole document. If you only want to change part of the document, you need to insert a Section break before and/or after the part you want to change, then only reformat the Section you want to change.

    For what you've described, it seems you need:
                int oStart = app.Selection.Range.Start;
                int oEnd = app.Selection.Range.End;
                Range oRng = app.Selection.Range;
                oRng.Sections.Add oRng.Characters.First;
                oRng.PageSetup.Orientation = WdOrientation.wdOrientLandscape;


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by StarMush Thursday, January 6, 2011 4:20 AM
    Wednesday, January 5, 2011 10:04 AM

All replies

  • Hi Mush,

    Your code is written to change the layout of the whole document. If you only want to change part of the document, you need to insert a Section break before and/or after the part you want to change, then only reformat the Section you want to change.

    For what you've described, it seems you need:
                int oStart = app.Selection.Range.Start;
                int oEnd = app.Selection.Range.End;
                Range oRng = app.Selection.Range;
                oRng.Sections.Add oRng.Characters.First;
                oRng.PageSetup.Orientation = WdOrientation.wdOrientLandscape;


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by StarMush Thursday, January 6, 2011 4:20 AM
    Wednesday, January 5, 2011 10:04 AM
  • hi macropod, thks 4 replying

    ya figured it out yesterday n did apply a section break, then obtain the range from where the cursor is to end of document

    so zat i can obtain the number of sections the doc contains frm cursor posn to end of doc

    zat way i change these sections to landscape if it was potrait or vice versa

    resulting in wat i wanted

    meaning: changing my doc to landscape if it was portrait n vice versa from my cursor posn till end of doc (also adjusted the tables in those sections)

    thanks again 4 replying macropod

    Mush

    :)

    Thursday, January 6, 2011 4:20 AM