Resizing Microsoft Word Window

Having trouble resizing the main window of the frontmost/active document.

I have the following but no joy…

tell application "Microsoft Word"
	activate
	set frntwindow to window number of active window of active document --set CurrentDocument to active document
end tell
tell application "System Events"
	tell process "Microsoft Word"
		set size of window frntwindow to {980, 775}
		delay 0.3
		click menu item "Zoom..." of menu 1 of menu bar item "View" of menu bar 1
		click radio button "Whole page" of radio group 1 of group 1 of window "Zoom"
		keystroke "A" using command down
		keystroke "150%"
		keystroke return
	end tell
end tell
/applescript]

The window resizing simply does not work. Any suggestions? Getting late over here.

Thanks

Sorry, mishit the applescript delimiter…

tell application "Microsoft Word"
	activate
	set frntwindow to window number of active window of active document --set CurrentDocument to active document
end tell
tell application "System Events"
	tell process "Microsoft Word"
		set size of window frntwindow to {980, 775}
		delay 0.3
		click menu item "Zoom..." of menu 1 of menu bar item "View" of menu bar 1
		click radio button "Whole page" of radio group 1 of group 1 of window "Zoom"
		keystroke "A" using command down
		keystroke "150%"
		keystroke return
	end tell
end tell

Unable to do size

but one of these might do ?

tell application "Microsoft Word"
	activate
	set width of active window to 980
	set height of active window to 775
	set position of active window to {980, 775}
	set percentage of zoom of view of active window to 150
end tell

or maybe bounds of active window ?

Val

Thanks for this, Val

Works great.

Is there any way of scripting the other zoom functions without GUI scripting - the “Page Width”, “Whole Page” and “Many Pages:” options?

Cheers

Perhaps consult http://download.microsoft.com/download/1/3/e/13e8ae25-78f7-41a8-b252-f09c465ce29c/word2004applescriptref.pdf

Though it refers to Word 2004 most of it applies to current version as well.

or tell application system events to get properties of window, menu item, etc etc.

Am quite new to this. So my information may be somewhat limited.

Some of the Microsoft implementation appears to me to be quite weird. But c’est la vie !

Val

Thanks.

I have found that by setting the bounds of the window, and setting zoom as per Val’s scripts, the window will automatically adjust to display the maximum number of pages possible. So I have a working solution without GUI scripting.

Below is the snippet of code, which I assign to a hot key and which progressively cycles through 1 to 3 page view of the active Word document on an external monitor. Numbers will need changing for any given set up of monitors. I have a 13" MacBook Pro (res 1280x800) and a 24" external monitor (res 1920x1080)

Cheers

tell application "Microsoft Word"
						set offstx to 1280
						set widths to {690 + offstx, 1290 + offstx, 1920 + offstx}
						set nwidth to item 2 of widths
						set pos_y to position of active window
						if item 1 of pos_y is greater than or equal to offstx then
							set curwidth to bounds of active window
							set curwidth to item 3 of curwidth
							if curwidth is greater than or equal to item 1 of widths and curwidth is less than item 2 of widths then
								set nwidth to item 2 of widths
							else if curwidth is greater than or equal to item 2 of widths and curwidth is less than item 3 of widths then
								set nwidth to item 3 of widths
							else if curwidth is greater than item 2 of widths then
								set nwidth to item 1 of widths
							end if
						end if
						set bounds of active window to {1280, 0, nwidth, 1080}
						delay 0.3
						set percentage of zoom of view of active window to 102
					end tell

Was looking for exactly the same thing. In the end, worked it out as follows:

tell application "Microsoft Word.app"
	set page fit of zoom of view of active window to page fit best fit
end tell