Simultaneously Changing the Format of 1200+ Word Documents
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?
Comments
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.
What's the status of AppleScripting in Word?
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.
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?
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.
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
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.
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?
Attachment 117
Testing out the attachment feature....
What editor is that?
I'd be lost without it. It shows you EVERYTHING about everything, trace, breakpoints, you name it.
http://www.latenightsw.com
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.
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.
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.
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?
So with the lines of code to set the margins changed, the script is
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.
I guess I should learn Applescript.
Glad to be of service.
The last one worked. You just saved me hours upon hours of time. Thank you so much.
I guess I should learn Applescript.