Changing Section Page Setup

V

vicw

I am having problems getting some VBA code to work and am confused by the
values being returned from Word. So far I have not found any helpful
information on the web or inseveral books (not encouraging!).

I use AuthorIT to publish to Word (2003 SP2) and am working on a document
the has mostly Portrtait pages, but has a couple of Landscape pages in the
middle. When the Landscape pages are published, their Page Setup is Portrait
/ Letter Rotated 8.5 x 11 (probably a mapping disconnect between AuthorIT and
Word??). When I try to print these pages, the printers (and I have tried
several) all prompt for 11 x 17 paper!

To overcome this problem, I am trying to write a macro to iterate through
the Sections and when I find a section that is defined as Portrait, but has a
Page Width of 11 inches I want to convert that section's page setup to
Portrait / 8.5 x 11.

Word seems to have a Construct for Portrait of 0 and Lanscape of 1. It also
seems to store page widths and heights in points instead of inches (maybe?),
since the values I receive are 612 and 792.1.

I have tried several things to change the section's page setup , but get
errors on the line indicated in the code below.

==================================================================

Sub ConverttoLandscape()
'
' AuthorIT publishes Landscape media objects to Word as Portrait/Letter
Rotated layouts
' These parameters must be changed to Landscape/Letter
'
Dim oSct As Section
Dim iSection As Integer
'
iSection = 1
'
For Each oSct In ActiveDocument.Sections
'
If oSct.PageSetup.Orientation = 0 And _
oSct.PageSetup.PageWidth = 792.1 Then
MsgBox "Found an illegitimate Portrait section!", vbOKOnly
'
With ActiveDocument.Sections(iSection).PageSetup
.Orientation = wdOrientLandscape ' errors and stops on
this line
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
End With
'
ElseIf oSct.PageSetup.Orientation = 0 And _
oSct.PageSetup.PageWidth = 612 Then
MsgBox "Found a legitimate Portrait section!", vbOKOnly
Else
MsgBox "Found a weird section!", vbOKOnly
End If
'MsgBox "Section " & iSection & " done.", vbOKOnly
'
iSection = iSection + 1
'
Next oSct
'
End Sub
================================================================
 
D

Dave Lett

Hi,

What's the error number/description? Also, yes, PageHeight and PageWidth
will return in points. You can use the PointsToInches and InchesToPoints
method to go back and forth, as in the following:

ElseIf oSct.PageSetup.Orientation = wdOrientPortrait And _
oSct.PageSetup.PageWidth = InchesToPoints(8.5)

or
ElseIf oSct.PageSetup.Orientation = wdOrientPortrait And _
PointsToInches(oSct.PageSetup.PageWidth) = 8.5

They say exactly the same thing, really.
On a side note, how do you like AuthorIt. We're looking at that product now.

Dave
 
V

vicw

--
Thanks in advance!


Dave Lett said:
Hi,

What's the error number/description? Also, yes, PageHeight and PageWidth
will return in points. You can use the PointsToInches and InchesToPoints
method to go back and forth, as in the following:

ElseIf oSct.PageSetup.Orientation = wdOrientPortrait And _
oSct.PageSetup.PageWidth = InchesToPoints(8.5)

or
ElseIf oSct.PageSetup.Orientation = wdOrientPortrait And _
PointsToInches(oSct.PageSetup.PageWidth) = 8.5

They say exactly the same thing, really.
On a side note, how do you like AuthorIt. We're looking at that product now.

Dave

Thanks for the response. The error is 4605 "Command is not available".
Seems like Word does not like the .Orientation property for Section
PageSetups -- it seems to like it for the entire document though?

I commonly use Letter Portrait (8.5" x 11") and Letter Landscape (11" x
8.5"), so my AuthorIT media object is set for Letter (8.5" x 11") Landscape.
However, when AuthoprIT publishes this section it sets the Word section Page
Setup to Portrait Letter Rotated 11 x 8.5. When I send the document to any
printer, the printer is prompting me to insert 11 x 17 paper????

My intent for the macro is to iterate through all sections and when finding
this "bad" setup change it to Landscape Letter 11 x 8.5. The macro I have
causes an error on the line I indicated -- like Word does not comprehend the
..Orientation property (for a section) or I am using it incorrectly. If I
manually change the "bad" section to Landscape, it prints correctly.

I tried AuthroIT's suggestion to make the template default Page Size =
Landscape. This worked fine until I tried to print and found that the Revert
to Portrait section following the now correct Landscape section was set to
Portrait Letter Rotated 11 x 8.5 and the printer again prompted me to insert
11 x 17 paper.

We have been using AuthorIT for about 18 months and I personally like it
very much for my printed docs. We also have some folks using it for Online
Help (WinHelp & HTML) and it also seems to serve their purposes well. There
have been a few minor issues, but with printed docs you always have the
option of writing post-publishing macros to overcome them -- until now!
OBTW, we moved from FrameMaker and RoboHELP to AuthorIT; primarily for the
single-sourcing to avoid duplication and maintain consistency.
 
D

Dave Lett

Hi,

The following seems to work on my computer. It doesn't raise an error when I
run the routine.

Sub ConverttoLandscape()
'
' AuthorIT publishes Landscape media objects to Word as Portrait/Letter
Rotated layouts
' These parameters must be changed to Landscape/Letter
'
Dim iSct As Integer
'
'
For iSct = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(iSct).PageSetup
If .Orientation = wdOrientPortrait And _
.PageWidth = InchesToPoints(11) Then
Debug.Print "Found an illegitimate Portrait section!" & iSct

'''reset the orientation and page size settings
.Orientation = wdOrientLandscape ' errors and stops on
this Line
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
ElseIf .Orientation = wdOrientPortrait And _
.PageWidth = InchesToPoints(8.5) Then
Debug.Print "Found a legitimate Portrait section!" & iSct
Else
Debug.Print "Found a weird section!" & iSct
End If
Debug.Print "Section " & iSct & " done."
End With
'
Next iSct
'
End Sub

When I was using a different software application, I had problems with my
printer automatically printing on 11 X 17 when it was a landscape 11 X 8.5.
I solved that problem by specifying that the printer was to use only tray X
(where X represents the tray that contains 11 X 8.5 paper).

Thanks for the AuthorIt information. My group will be using it both ways:
developing printed docs and online help. It's nice to hear the good news.

HTH,
Dave
 
V

vicw

Thanks Dave. The error is gone, but the print problem still exists. I am
printing to a tray that contains the proper paper and the print settings are
correct.

The code runs without causing an error, but the Page Setup dialog for that
section still shows Portrait, Letter Rotated, 11 x 8.5, so I don't think it
is actually changing the settings in Word.

When I manually change the settings on the dialog to Landscape all is well
-- even the printing. If I can just get the code to do what I am doing
manually, the world will be in harmony again!

.. . .
 
D

Dave Lett

Can you send me a copy (or a portion of a copy) of the document?
davedotlettatplateaudotcom

Obviously, replace dot with "." and the "at" after my name with "@" but
don't replace the second "@".

I've never seen "Letter Rotated".

Dave
 
D

Dave Lett

Hi,

Try this (it worked on my machine). I was having issues with the other
method, too.

Dim iSct As Integer
For iSct = 1 To ActiveDocument.Sections.Count
Selection.GoTo What:=wdGoToSection, Count:=iSct
Selection.EndOf Unit:=wdSection, Extend:=wdMove

With Dialogs(wdDialogFilePageSetup)
If .Orientation = wdOrientPortrait And _
Left(.PageWidth, 2) = 11 Then
Debug.Print True
.Orientation = wdOrientLandscape
.Execute
End If
End With

Next iSct

HTH,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top