分开处理,先处理页眉。在使用同样的代码设置页脚,不要混在一起使用
Dim app As New MSWord.Application
try
Dim doc0 As Object = app.Documents.Open("d:\test2.docx")
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader
app.ActiveWindow.Selection.WholeStory
app.ActiveWindow.Selection.Copy
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument
Doc0.Close
Dim fileName = "d:\test.docx"
Dim doc As Object = app.Documents.Open(fileName)
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader
app.ActiveWindow.Selection.WholeStory
app.ActiveWindow.Selection.TypeBackspace
app.ActiveWindow.Selection.Paste
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument
这里复制上面代码另外处理页脚
app.Visible = True
catch ex As exception
msgbox(ex.message)
app.Quit
finally
'app.Quit
End try