PDA

View Full Version : Page Orientation



Falco
08-08-2019, 02:12 PM
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.

gmayor
08-08-2019, 10:54 PM
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

Falco
08-09-2019, 08:46 AM
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.

gmayor
08-09-2019, 11:05 PM
The code as posted works in all Word versions from 2003 to the present.

Falco
08-13-2019, 01:19 PM
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?

Falco
08-13-2019, 01:49 PM
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.