Page setup automation from vb

R

Richard Bond

Hi,

I'm trying to automate word 2000/XP from VB. I have late
bound to the Word application and am trying to set the
document to landscape (other VBA code has worked).
However the code does not seem to work, I then tried to
use sendKeys , but that didn't work either. Can anyone
help out please?

Here is the code:

Const wdOrientPortrait = 0

With oWordApp

.ActiveDocument.PageSetup.Orientation = wdOrientPortrait

End With

'or (version specific)

oWordApp.Activate
WaitPlease(0.5) ' Waits 0.5 sec.
SendKeys "%F", 1 ' Alt + F = File
SendKeys "%u", 1 ' Alt + u = Page setup
SendKeys "%s", 1 ' Alt + s = Landscape

thanks for any help,

Richard
 
J

Jonathan West

If you want landscape orientation, you aren't going to achieve much by
setting the orientation to portrait, which is what your first code sample is
doing. Try this instead

Const wdOrientLandscape = 1

With oWordApp

.ActiveDocument.PageSetup.Orientation = wdOrientLandscape

End With
 

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