출발점.
$wd = new-object -comobject word.application # create a com object interface (word application)
$wd.documents.open("C:\word\test.doc") # open doc
$wd.run("Macro01") # exec macro named macro01 that add custom footer and/or header
$wd.quit() # exit application
macro
해야 :
이
function Add-PageFooter ([string]$Document) {
add-type -AssemblyName "Microsoft.Office.Interop.Word"
set-variable -name wdAlignPageNumberCenter -value 1 -option constant
$fc1 = "Page"
$word = New-Object -comobject Word.Application
$Word.Visible = $True
#$Word.Visible = $False
$fc2 = [ref] "" -as [Type]
$OpenDoc = $Word.Documents.Open($Document)
$c = $OpenDoc.Sections.Item(1).Footers.Item(1).PageNumbers.Add($wdAlignPageNumberCenter)
$range1 = $openDoc.Sections.Item(1).Footers.Item(1).range
$field1 = $OpenDoc.Fields.Add($range1, -1, $fc2)
$field1.Code.Text = $fc1
$field1.Update
#$OpenDoc.Close()
}
또 다른 방법은 워드 Macro
를 작성하고 파워 쉘에서 실행하는 것입니다 :이 기능은 매개 변수로 전달 된 문서의 바닥 글에 페이지 번호를 추가 (워드 2010 사용) 열려있는 모든 문서에 normal.dot
(2010 년 이상은 normal.dotm
)으로 저장해야합니다.
이렇게하면 워드 문서에서 원하는 내용을 사용자 정의 할 수 있으며 매크로의 머리글/바닥 글 녹음은 문서의 작업을 사용자 정의 할 수 있습니다.