or Connect
AppleInsider › Forums › General › Genius Bar › Simultaneously Changing the Format of 1200+ Word Documents
New Posts  All Forums:Forum Nav:

Simultaneously Changing the Format of 1200+ Word Documents

post #1 of 16
Thread Starter 
I have about 1200 Word documents that I have downloaded from Lexis (cases, law review articles). The problem is that the documents have more than 1" margins on all four corners, so I have to change the fomatting to each document when I open it. Is there any way to change the top, bottom, left, right margins to .5" to multiple documents at the same time?
post #2 of 16
What's the status of AppleScripting in Word?
My brain is hung like a HORSE!
Reply
My brain is hung like a HORSE!
Reply
post #3 of 16
That's a lotta paper. Not sure how to do it, but I'm gonna keep an eye on this one.
'L'enfer, c'est les autres' - JPS
Reply
'L'enfer, c'est les autres' - JPS
Reply
post #4 of 16
I can't get Word X to script at all.

I think MS wants you to use VBA for that generation of product.

I don't have Word 2004 to test.

Somebody drop Word 2004's icon on the Script Editor's icon and let's see what it says.

Quote:
Originally Posted by Kickaha

What's the status of AppleScripting in Word?
--Johnny
Reply
--Johnny
Reply
post #5 of 16
Quote:
Originally Posted by lundy

Somebody drop Word 2004's icon on the Script Editor's icon and let's see what it says.

Looking through it there is a lot of scripting promise, including the ability to change the margins. I'm pretty new to Applescript, but the following code will change the margin of the active (front) document.

Code:

tell application "Microsoft Word"
set left margin of page setup of active document to (inches to points inches 0.5)
end tell



Sounds like lundy and kickaha know what they're talking about and can turn this into an automative script?
Daniel Tull
Reply
Daniel Tull
Reply
post #6 of 16
This script should get you started.
You should specify the margins in the "myMargin" line.
You should put the 1200 documents in a folder and put the path of it in the third line.
I can't test it, but it should save each file in the location specified by the path in the "Close Window" line.

Test it with 2 or so files in the source folder. There will probably be errors - post back and we will debug it.


Code:


set myMargin to {myTop:0.1, myBottom:0.2, myLeft:0.3, myRight:0.4}
tell application "Finder"
set theFiles to files of folder "myTestFolder" of desktop
set theOutputPath to folder "OutputFolder" of desktop
repeat with theFile in theFiles
open theFile
set theFileName to displayed name of theFile
tell application "Microsoft Word"
tell front document
tell section 1
set top margin to myMargin's myTop
set bottom margin to myMargin's myBottom
set left margin to myMargin's myLeft
set right margin to myMargin's myRight
set theDestination to (theOutputPath as string) & theFileName
close document 1 saving yes saving in file theDestination
end tell
end tell
end tell
end repeat
end tell




Quote:
Originally Posted by danielctull

Looking through it there is a lot of scripting promise, including the ability to change the margins. I'm pretty new to Applescript, but the following code will change the margin of the active (front) document.

Code:

tell application "Microsoft Word"
set left margin of page setup of active document to (inches to points inches 0.5)
end tell



Sounds like lundy and kickaha know what they're talking about and can turn this into an automative script?
--Johnny
Reply
--Johnny
Reply
post #7 of 16
Testing out the attachment feature....


Attachment 117
LL
--Johnny
Reply
--Johnny
Reply
post #8 of 16
Quote:
Originally Posted by lundy

Testing out the attachment feature....

What editor is that?
Daniel Tull
Reply
Daniel Tull
Reply
post #9 of 16
Script Debugger 4.0.

I'd be lost without it. It shows you EVERYTHING about everything, trace, breakpoints, you name it.

http://www.latenightsw.com
--Johnny
Reply
--Johnny
Reply
post #10 of 16
Thread Starter 
Quote:
Originally Posted by lundy

This script should get you started.
Test it with 2 or so files in the source folder. There will probably be errors - post back and we will debug it.
[/code]

Hey Lundy: Thank you for helping me with this and for taking your time to write this Applescript.

1. I ran the script with a test folder with two files and received the following error:

Microsoft Word got an error: Can't set top margin of section 1 of document 1 to 0.5.

2. I tried running the scipt on the folder with all of the documents and received this error. Does it matter that the files are in subfolders? Should I specify the subfolders that the files are in?

Finder got an error: Can't get every file of folder "A.Law" of desktop.

Once again. Thanks.
post #11 of 16
Quote:
Originally Posted by Neruda

Hey Lundy: Thank you for helping me with this and for taking your time to write this Applescript.

1. I ran the script with a test folder with two files and received the following error:

Microsoft Word got an error: Can't set top margin of section 1 of document 1 to 0.5.

Bummer. It works PERFECTLY on my machine, with Word X. I gave it a folder of about 20 files and it changed all the margins and put them in the output folder.

I forgot to mention that you have to make sure that Word is open but with no documents open before running the script. I do not have Word 2004, so there may be changes in the AppleScript syntax (I know there is between Excel X and Excel 2004).

Post your script and let me make sure it looks OK.
Quote:
2. I tried running the scipt on the folder with all of the documents and received this error. Does it matter that the files are in subfolders? Should I specify the subfolders that the files are in?

Finder got an error: Can't get every file of folder "A.Law" of desktop.

Once again. Thanks.

Yeah - I did not write it to recurse on subfolders, since it is a one-shot deal. Just pile all the documents into one folder. The reason it is choking is that "every file" is choking when it sees a folder.

Again post your code so I can take a look. ALSO - if you have Word X for Mac, try that to see if there is some syntactical change.
--Johnny
Reply
--Johnny
Reply
post #12 of 16
The only reason I can think of for the Word error is if there is no document 1 open. I just tested that single line on a manually-opened document and it worked, no problem.

It could be that the Finder barfed on the "every file" phrase, since there were folders in there, and then Word barfed because the Finder didn't open the file.

Would it be easier for you if I re-wrote it to allow you to choose the input (and possibly output) folders, and you could do it one folder at a time, or is it OK for you to lump all the input files together in one folder without running into duplicate file names?
--Johnny
Reply
--Johnny
Reply
post #13 of 16
OK - I got the Word 2004 AppleScript Reference and the syntax I was using for margins was deleted and replaced by the "Page Setup" syntax mentioned above.

So with the lines of code to set the margins changed, the script is


Code:


set myMargin to {myTop:0.1, myBottom:0.2, myLeft:0.3, myRight:0.4}
tell application "Finder"
set theFiles to files of folder "myTestFolder" of desktop
set theOutputPath to folder "OutputFolder" of desktop
repeat with theFile in theFiles
open theFile
set theFileName to displayed name of theFile
tell application "Microsoft Word"
tell front document
set right margin of page setup to inches to points inches (myMargin's myRight)
set left margin of page setup to inches to points inches (myMargin's myLeft)
set top margin of page setup to inches to points inches (myMargin's myTop)
set bottom margin of page setup to inches to points inches (myMargin's myBottom)

set theDestination to (theOutputPath as string) & theFileName
close document 1 saving yes saving in file theDestination
end tell
end tell
end repeat
end tell



But I cannot test it as I do not have Word 2004.

We are almost there - we'll get it. There may be syntax changes in opening and saving the file, too - I am looking into that.
--Johnny
Reply
--Johnny
Reply
post #14 of 16
Thread Starter 
The last one worked. You just saved me hours upon hours of time. Thank you so much.

I guess I should learn Applescript.
post #15 of 16
*Cracks knuckles*

Glad to be of service.
My brain is hung like a HORSE!
Reply
My brain is hung like a HORSE!
Reply
post #16 of 16
Fabulous! And I couldn't even test it. Sometimes luck is with you.


Quote:
Originally Posted by Neruda

The last one worked. You just saved me hours upon hours of time. Thank you so much.

I guess I should learn Applescript.
--Johnny
Reply
--Johnny
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Genius Bar
AppleInsider › Forums › General › Genius Bar › Simultaneously Changing the Format of 1200+ Word Documents