MVP Barry Wainwright & MVP Daiya Mitchellresize windows applescript.

L

l2oBiN

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

I would like to refreer to the code script located

<http://word.mvps.org/mac/scripts/windowsize.html>

provided by MVP Barry Wainwright, presented by MVP Daiya Mitchell in February 2008.

This script applies the settings to a single word window "active". I would like to apply it to all open word windows. How could I do that? (the script is below).

(* This is a sample applescript that allows you to change the settings of a Word 2008 document in a single click. This one controls the size and location of the window, the view it uses, the degree of zoom, and which toolbars appear. You would need to customize this sample to fit your preferences.

Please see the article at <http://word.mvps.org/mac/scripts/WindowSize.html&gt <http://word.mvps.org/mac/scripts/WindowSize.html&gt>;

Code provided by MVP Barry Wainwright, presented by MVP Daiya Mitchell in February 2008

USE AT YOUR OWN RISK. Test on dummy documents. Please see <http://word.mvps.org/mac/scripts/&gt <http://word.mvps.org/mac/scripts/&gt>;

Tested in OS X 10.4.11 (PPC) and Office 2008
* )

tell application "Microsoft Word"
activate

--set the View. Instead of "page view", you can substitute any of the following: normal view/draft view/outline view/page view/master view/online view
 
J

John McGhie

This is not as easy as it sounds.

You cannot modify Barry's script particularly easily, for several reasons:
the main one is that he is using a shorthand to avoid having to find all the
documents and all the windows you have open.

Here's the normal way to do it (in VBA....)

Sub WindowSize()

Dim aDocument As Document
Dim aWindow As Window

For Each aDocument In Application.Documents
For Each aWindow In aDocument.Windows
With aWindow
.View.Type = wdPrintView
.View.Zoom.Percentage = 100
.WindowState = wdWindowStateNormal
.Top = 5
.Left = 5
.Height = (Application.UsableHeight * 0.5)
.Width = (Application.UsableWidth * 0.5)
End With
Next aWindow
Next aDocument
End Sub

The "Tell Application" construct is missing from VBA because we are already
"inside" Microsoft Word so we do not need to say which application we want.

Then we need to run a loop to process all the documents Word has open. Word
can have up to about a hundred documents open at a time: and each of those
documents can have several windows open.

Barry handles this problem by using "Activate" which brings Word to the
front and makes the front-most document active. He can then address
"ActiveWindow" because there can now be only one.

However, if you want to do something to all of the Word windows, you must
first iterate all of the documents, then iterate each of the windows of each
of those documents in turn. So you have a doubly-nested loop, the outer
level gets each document, then the inner level gets each Window.

To keep the code compact, I am using the "With" construct to avoid having to
code the name of the document and the name of the window on each line. Each
of the statements within the "With" object apply to the "window we are
currently working on".

I then set a few properties to show you how. Be careful of "WindowState":
if that's not Normal ( wdWindowStateNormal) then Word is either maximised or
minimised and the height and width properties will have no effect.

In this case, I am using asking the 'Application" (which we already agreed
can only be Word) to tell me what its "useable height" and "useable width"
are. These values come back in points (which is silly, but I didn't design
this...)

But I don't care: by multiplying them by 0.5 I am setting this window to
take half the available space on your screen: you can adjust that as you
wish. Or you can simply set WindowState to wdWindowStateMaximize, which
sets it to the maximum size available. Then you do not need the top, left,
height and width lines at all.

So: That's how you do it. You just need to convert that code to
applescript.

Oh: One other point: The documents must of course be "open" and each
document must have at least one "window" for this to work. By constructing a
"For ... Each ... Next" loop the way I have, the code avoids this issue: the
loops will harmlessly do nothing if there are no documents or windows
currently open.

Hope this helps


Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

I would like to refreer to the code script located

<http://word.mvps.org/mac/scripts/windowsize.html>

provided by MVP Barry Wainwright, presented by MVP Daiya Mitchell in February
2008.

This script applies the settings to a single word window "active". I would
like to apply it to all open word windows. How could I do that? (the script is
below).

(* This is a sample applescript that allows you to change the settings of a
Word 2008 document in a single click. This one controls the size and location
of the window, the view it uses, the degree of zoom, and which toolbars
appear. You would need to customize this sample to fit your preferences.

Please see the article at <http://word.mvps.org/mac/scripts/WindowSize.html&gt
<http://word.mvps.org/mac/scripts/WindowSize.html&gt>;

Code provided by MVP Barry Wainwright, presented by MVP Daiya Mitchell in
February 2008

USE AT YOUR OWN RISK. Test on dummy documents. Please see
<http://word.mvps.org/mac/scripts/&gt <http://word.mvps.org/mac/scripts/&gt>;

Tested in OS X 10.4.11 (PPC) and Office 2008
* )

tell application "Microsoft Word"
activate

--set the View. Instead of "page view", you can substitute any of the
following: normal view/draft view/outline view/page view/master view/online
view

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

--

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:[email protected]
 
S

Shawn Larson [MSFT]

I'm hoping all you'll need to do is loop through all your open windows. I'm
using a bit of shorthand myself, as John mentions below, because I'm not
concerned with what type of window is opened, just all opened windows.

tell application "Microsoft Word"
activate

set intCountOfWindows to count of windows

repeat with loopVar from 1 to intCountOfWindows
set bounds of (window loopVar) to {41, 56, 662, 854}
set view type of view of (window loopVar) to draft view
set percentage of zoom of view of (window loopVar) to 125
end repeat
end tell

Once the count of windows is done, the loop goes through all open windows,
sets the size, view, and percentage.

--
Shawn Larson
Microsoft MacBU
Mac Word Test

This posting is provided *AS IS* with no warranties, and confers no rights.
Please do not send email directly to this e-mail address. It is for
newsgroup purposes only.

Find out everything about Microsoft Mac Newsgroups at:
[http://www.officeformac.com/productforums]
Check out product updates, news and info at:
[http://www.microsoft.com/mac]
 
J

John McGhie

Thanks Shaun:

You just had to make yours nicer than mine, didn't you :)

That might just find its way onto the MVPS website :)

Cheers


I'm hoping all you'll need to do is loop through all your open windows. I'm
using a bit of shorthand myself, as John mentions below, because I'm not
concerned with what type of window is opened, just all opened windows.

tell application "Microsoft Word"
activate

set intCountOfWindows to count of windows

repeat with loopVar from 1 to intCountOfWindows
set bounds of (window loopVar) to {41, 56, 662, 854}
set view type of view of (window loopVar) to draft view
set percentage of zoom of view of (window loopVar) to 125
end repeat
end tell

Once the count of windows is done, the loop goes through all open windows,
sets the size, view, and percentage.

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

--

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:[email protected]
 
J

JE McGimpsey

Shawn Larson said:
I'm hoping all you'll need to do is loop through all your open windows. I'm
using a bit of shorthand myself, as John mentions below, because I'm not
concerned with what type of window is opened, just all opened windows.

tell application "Microsoft Word"
activate

set intCountOfWindows to count of windows

repeat with loopVar from 1 to intCountOfWindows
set bounds of (window loopVar) to {41, 56, 662, 854}
set view type of view of (window loopVar) to draft view
set percentage of zoom of view of (window loopVar) to 125
end repeat
end tell

Once the count of windows is done, the loop goes through all open windows,
sets the size, view, and percentage.

Note that this will barf a run-time error if any non-draft-view windows
are minimized (an almost constant state for me). Better:

tell application "Microsoft Word"
repeat with loopVar from 1 to count of windows
if not window state of (window loopVar) is ?
window state minimize then
set bounds of (window loopVar) to {41, 56, 662, 854}
set view type of view of (window loopVar) to draft view
set percentage of zoom of view of (window loopVar) to 125
end if
end repeat
end tell
 

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