PageSetup - Orientation on Landscape

T

Torsten Hansen

Hello,

I want to start Word from another programm (Excel, Access, FrontPage...)
with a little makro and set the orientation in the PageSetup-Menue on
"Landscape", but it doesn't work.
Word starts but the orientation has not been set on "Landscape".
Does anybody know what's wrong in my makro?

Sub Test()
Dim WordObj As Object
Dim WordDoc As Object
On Error Resume Next
Set WordObj = GetObject(, "Word.Application.10")
If Err.Number = 429 Then
Set WordObj = CreateObject("Word.Application.10")
Err.Number = 0
End If
WordObj.Visible = True
Set WordDoc = WordObj.Documents.Add

WordObj.ActiveDocument.PageSetup.Orientation = wdOrientLandscape

Set WordDoc = Nothing
Set WordObj = Nothing
End Sub

Thanks!

Torsten
 
D

Doug Robbins - Word MVP

Hi Torsten,

The easiest thing to do is create a template that has its orientation set to
landscape and have your code create a new document from that template.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
R

Richard

Try this...

WordObj.Visible = True
Set WordDoc = WordObj.Documents.Add

PauseTime = 1 ' Set duration. Set for 1
second...Change if needed
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer

WordObj.ActiveDocument.PageSetup.Orientation =
wdOrientLandscape

Set WordDoc = Nothing


(((Note Code to wait for a second is taken from the
Word2002 Help file.... VBAOF10.CHM... with a small
adjustment to time.))

I got a feeling your code is asking word to change the
orientation before it can actually initialize Word.
So you may need to add a little bit of a delay for the
word to respond to it.

I'm not a pro at programming... I just had something
similar happen to me in my code when trying to open a new
document.
 
H

Helmut Weber

Hi Torsten,
you are using "late binding". That's the method
with getobject oder createobject. In that case
"wdOrientLandscape" is unknown to Excel.
You may use 1, the integer equivalent instead.
Or you to set a reference to the Word-Library in Excel,
that is "early binding".
Then you my use the word-constants.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
T

Torsten Hansen

Hallo Helmut,

da Du ja aus "Bavaria" kommst, kann ich Dir ja auf Deutsch "Danke" sagen ;)

Viele Grüße,

Torsten
 

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