August 31st, 2006

How Can I Set the Document Orientation in Microsoft Word to Landscape?

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I set the document orientation in Microsoft Word to landscape?

— EE

SpacerHey, Scripting Guy! AnswerScript Center

Hey, EE. We think the script that we’re about to show you will answer your question; if it doesn’t, however, we’ll hope you cut us a little slack. After all, according to an exercise bike at the local gym, the Scripting Guy who writes this column died last night.

Now, don’t worry: the Scripting Guy actually feels pretty good. (Maybe death is overrated.) What happened is this: Last night the Scripting Guy who writes this column and his Scripting Son went to workout at the gym. After playing some basketball they sat down to ride the exercise bikes. As they started, the Scripting Guy who writes this column noticed that, even though he wasn’t holding on to the heart rate monitor, the exercise bike insisted that his heart rate was 140. Oh, well, he thought; who cares?

A few minutes into the workout, however, he noticed that every 10 seconds or so his heart rate would suddenly drop by a few beats (even though he still wasn’t gripping the heart rate monitor). At first he liked that: after all, having such a low heart rate while working out was proof of the great shape he’s in. As his alleged heart rate continued to drop, however, he began to worry; as his heart rate dipped into the 40s he really began to worry. And then, suddenly, his heart rate started falling, beat-by-beat, until the heart rate monitor measured 0. No heart beat? That didn’t sound very good.

Note. Admittedly, heart rate isn’t necessarily the criteria used to determine whether someone is dead or alive; often times death is indicated by absence of any sort of brain activity. However, that methodology can’t be applied to the Scripting Guy who writes this column; if it could, he would have been declared dead years ago.

So was the Scripting Son alarmed at the fact that, according to the exercise bike, the Scripting Dad no longer had a heart beat? Not exactly. Although they still had a good 10 minutes or so left in their workout the Scripting Dad thought the fact that he was dead should give him the right to quit early. The Scripting Son would have no part of that, however; instead, he insisted that his poor deceased father continue riding for the last 10 minutes, even forcing him – as is their custom – to sprint the final minute.

Which, when you think about it, was really pretty impressive. After all, anyone can ride a bike while they’re alive; however, we’re willing to bet that even Lance Armstrong himself would have trouble riding a bike while dead.

Note. Did the Scripting Guy’s life flash before his eyes when he died? That’s hard to say. Granted, he didn’t see anything interesting as the heart rate monitor counted down to 0. But, then again, he hasn’t really lived a very interesting life. So who knows?

Now, does all that mean that there won’t be a Hey, Scripting Guy! column today? Of course not; you don’t think a little thing like having no heartbeat could stop the Scripting Guys, do you? Here’s a script that sets the page orientation in Microsoft Word to landscape:

Const wdOrientLandscape = 1

Set objWord = CreateObject(“Word.Application”) objWord.Visible = True Set objDoc = objWord.Documents.Add()

objDoc.PageSetup.Orientation = wdOrientLandscape

As you can see, there’s not much to this script. We start out by defining a constant named wdOrientLandscape and setting the value to 1; we probably don’t need to tell you that we’ll use this constant to switch the page orientation to landscape. What if we decide later on to switch the orientation back to portrait mode? No problem; in that case we just need to use a constant named wdOrientPortrait and set the value of that constant to 0:

Const wdOrientPortrait = 0

After defining our constant we create an instance of the Word.Application object and set the Visible property to True; that gives us an instance of Microsoft Word that we can see on screen. We call the Add method to add a new document to our instance of Word, then use this line of code to change the page orientation to landscape:

objDoc.PageSetup.Orientation = wdOrientLandscape

Thatis easy, isn’t it?

All we’re doing in that line of code is assigning the constant wdOrientLandscape to the Orientation property of the PageSetup object (which happens to be a child object of the Document object). At that point our document will switch to landscape mode.

Of course, if you’re working in landscape mode you might want to do two additional things: you might want to ensure that the document is in Print Layout view (that way you can easily verify that the orientation really has been set to landscape) and you might want to change the Zoom (to ensure that the entire document fits on screen). Here’s a bonus script that changes the View to Print Layout and the Zoom to 80 percent:

Const wdOrientLandscape = 1
Const wdPrintView = 3 

Set objWord = CreateObject(“Word.Application”) objWord.Visible = True Set objDoc = objWord.Documents.Add()

objDoc.PageSetup.Orientation = wdOrientLandscape

objDoc.ActiveWindow.View.Type = wdPrintView objDoc.ActiveWindow.View.Zoom.Percentage = 75

We won’t bother explaining all this today; all we’re really doing is modifying the Type and Zoom properties of the ActiveWindow.View object. If you’d like to use a different view type (that is, something other than Print Layout), well, here’s a complete list of constants and their values:

Constant

Value

wdMasterView

5

wdNormalView

1

wdOutlineView

2

wdPrintPreview

4

wdPrintView

3

wdReadingView

7

wdWebView

6

Just substitute the appropriate constant (and value) for wdPrintView and have at it.

One last thing. The answer to the age-old question is this: yes, the fact that the Scripting Guy made it in to work today proves that there is life after death. The only drawback? Considering that he made it in to work suggests that our Scripting Guy didn’t quite make it to heaven, if you know what we mean.

And the fact that all the other Scripting Guys are here, too pretty much proves that, doesn’t it?

Author

0 comments

Discussion are closed.