Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of MS Word 2010 documents and I need to convert them from Letter page size to A4. Is there a simple way to do that? Possibly some PowerShell script combined with some MS Word API?

share|improve this question

2 Answers 2

Here is some VBA you can add as a macro to change all the Word documents in a given folder.

WARNING: Make a backup copy of your files prior to running this code.

Open a new Word document, paste this code into the VBA window (Alt+F11). Make necessary changes to the path, then close the window.

Sub ChangePaperSize()
Dim myFile As String
Dim myPath As String
Dim myDoc As Document

'Change to the path where your documents are located.
'This code changes ALL documents in the folder.
'You may want to move only the documents you want changed to seperate folder.
myPath = "C:\temp\"

'Closes open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges

'Set the path with file name for change
myFile = Dir$(myPath & "*.docx")

    Do While myFile <> ""

    'Open the document and make chages
    Set myDoc = Documents.Open(myPath & myFile)
    myDoc.PageSetup.PaperSize = wdPaperA4

    'Close and saving changes
    myDoc.Close SaveChanges:=wdSaveChanges

    'Next file
    myFile = Dir$()
    Loop
    msgbox "Process complete!"    
End Sub

Open the Macro window (Alt+F8) and choose ChangePaperSize, then click run. The current open document will close and other documents will open and close as it makes the changes to each document in the folder.

share|improve this answer
    
Excellent, thanks, that gave me enough clues to write the same thing in PowerShell (which I find easier to use). Will post the code as separate answer. –  Borek Sep 27 '12 at 19:02
    
Great. Glad to help. –  CharlieRB Sep 27 '12 at 19:13

PowerShell version based on CharlieRB's answer:

param(
    [parameter(position=0)]
    [string] $Path
)

$docFiles = (Get-ChildItem $Path -Include *.docx,*.doc -Recurse)

$word = New-Object -com Word.Application

foreach ($docFile in $docFiles) {

    $doc = $word.Documents.Open($docFile.FullName)
    $doc.PageSetup.PaperSize = [Microsoft.Office.Interop.Word.WdPaperSize]::wdPaperA4

    $doc.Save()
    $doc.Close()

}

$word.Quit()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.