Consulting

Results 1 to 6 of 6

Thread: Page Orientation

  1. #1
    VBAX Newbie
    Joined
    Aug 2019
    Posts
    4
    Location

    Page Orientation

    Hello, I'm working with a document with most of the pages having portrait orientation but some have landscape. This document has many tables and I want to make all the tables the same size and position (this I know how to do). There are special tables on the landscape pages that I want to leave alone. Is there a way for me to see the orientation of a single page? It seems ActiveDocument.PageSetup.Orientation is meant to check the orientation of the whole document. Ideally I want to iterate through all the tables and use an if statement to skip the ones that are found on landscape pages. Any advice is greatly appreciated.

  2. #2
    ActiveDocument.PageSetup.Orientation refers to the document. If you want to refer to a page then set a range to the page and check the pagesetup of that range or put the cursor in the page and then Selection.PageSetup.Orientation will return 0 for Portrait or 1 for Landscape. To iterate through the tables and process only those on a landscape page

    Dim oTable As Table    
        For Each oTable In ActiveDocument.Tables
            If oTable.Range.PageSetup.Orientation = wdOrientLandscape Then
                oTable.Cell(1, 1).Range.Text = "Landscape page" 'do something with oTable
            End If
        Next oTable
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Aug 2019
    Posts
    4
    Location
    Thanks, this is exactly what I needed. Although, I'm getting a 4605 error "command not available" associated with oTable.Range.PageSetup.Orientation. Not sure why, It partially worked before giving me that error.

  4. #4
    The code as posted works in all Word versions from 2003 to the present.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Aug 2019
    Posts
    4
    Location
    So I ran the code on a better document and it fixed 13 tables before returning a run-time error 4605. I look at the table that didn't get changed and it happens to break over multiple pages. I can see this being a problem, any ideas on how to fix this?

  6. #6
    VBAX Newbie
    Joined
    Aug 2019
    Posts
    4
    Location
    Okay I am truly confused now. I got another document and I tried to run the macro and it immediately gave me the 4605 error. Changing nothing, I tried again to run it and this time it went and changed 86 tables BUT they were slightly off from fixed, ex. 6.88 inches instead of 7 inches. I ran it a third time and still got an error 4605 on the 86th table but this time all 86 tables were 7 inches and aligned left with no text wrapping, which is the format I want.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •