none
Change orientation of Word Document using VSTO RRS feed

  • Question

  • I want to change the orientation of a word document from portrait to landscape through VSTO. I tried to convert the following VBA code to do so, but it generates an error at runtime.

     

    TogglePortrait(TAB:=3, PaperSize:=0, TopMargin:="1", _
           BottomMargin:="1", LeftMargin:="1", RightMargin:="1", Gutter:="0", _
           PageWidth:="11", PageHeight:="8.5", Orientation:=1, FirstPage:=0, _
           OtherPages:=0, VertAlign:=0, ApplyPropsTo:=0, FacingPages:=0, _
           HeaderDistance:="0.5", FooterDistance:="0.5", SectionStart:=2, _
           OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0, LineNum:=0, _
           StartingNum:=1, FromText:=0, CountBy:=0, NumMode:=0, _
           TwoOnOne:=0, GutterPosition:=0, LayoutMode:=0, CharsLine:=42, LinesPage:= _
           36, CharPitch:=220, LinePitch:=360, DocFontName:="+Body", DocFontSize:=11 _
           , PageColumns:=1, TextFlow:=0, FirstPageOnLeft:=0, SectionType:=1, _
           FolioPrint:=0, ReverseFolio:=0, FolioPages:=1)
    


    This was not directly copied from VBA. I DID change some VBA constants to their numerical values.

     

    And the error it generates:

     

    System.MissingMemberException was unhandled by user code
      'TogglePortrait' on type 'ApplicationClass' not found.

    i tried doing Application.TogglePortrait and Me.Application.TogglePortrait.

    Thanks in advance. I know that there are alot of people here that will be able to help me.


    Tanu Agg-Director of Awesomeness and All things Nerdy
    • Edited by Tanu Agg Friday, February 3, 2012 12:17 AM
    Friday, February 3, 2012 12:16 AM

Answers

  • Which version of Word are you working in and which programming language are you using?

    TogglePortrait is a member of the PageSetup object, which can be accessed via a Document or Section object.


    Cindy Meister, VSTO/Word MVP
    Friday, February 3, 2012 7:09 AM
    Moderator

All replies

  • Hi Tanu,

    I'm not sure if I got your question entirely and haven't used VBA or TogglePortrait, however in VSTO, you could try the PageSetup.Orientation property which takes values of type WdOrientation. In a document-level customization the code would look like

    ThisApplication.ActiveDocument.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
    
    ThisApplication.ActiveDocument.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait;
    

    Hope that helps.

    Avinash.


    Thanks, Avinash Nigam.
    Friday, February 3, 2012 2:21 AM
  • Which version of Word are you working in and which programming language are you using?

    TogglePortrait is a member of the PageSetup object, which can be accessed via a Document or Section object.


    Cindy Meister, VSTO/Word MVP
    Friday, February 3, 2012 7:09 AM
    Moderator
  • Oops, I realized that someone has opened such a question before. So, I better close this thread. Thank you for your help Avinash and Cindy!
    Tanu Agg-Director of Awesomeness and All things Nerdy
    Friday, February 3, 2012 11:18 PM