MS Word 파일을 Letter 페이지 크기에서 A4로 일괄 변환하는 방법은 무엇입니까?

MS Word 파일을 Letter 페이지 크기에서 A4로 일괄 변환하는 방법은 무엇입니까?

MS Word 2010 문서가 많이 있는데 Letter 페이지 크기에서 A4로 변환해야 합니다. 그렇게 하는 간단한 방법이 있나요? 아마도 일부 MS Word API와 결합된 일부 PowerShell 스크립트가 있을까요?

답변1

다음은 특정 폴더의 모든 Word 문서를 변경하기 위해 매크로로 추가할 수 있는 VBA입니다.

경고: 이 코드를 실행하기 전에 파일의 백업 복사본을 만드십시오.

새 Word 문서를 열고 이 코드를 VBA 창( Alt+ F11)에 붙여넣습니다. 경로를 필요에 따라 변경한 다음 창을 닫습니다.

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

매크로 창( Alt+ F8)을 열고 을 선택한 ChangePaperSize다음 실행을 클릭합니다. 폴더의 각 문서가 변경되면 현재 열려 있는 문서가 닫히고 다른 문서도 열리고 닫힙니다.

답변2

CharlieRB의 답변을 기반으로 한 PowerShell 버전:

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()

관련 정보