用word vba操作
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open("f:\123.doc")
With doc
.Activate
app.WordBasic.RemoveWatermark '删除旧的水印
For Each oSec As object In doc.Sections '文档的节中循环
Dim myRange = oSec.Headers(MSWord.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
myRange.Delete '删除页眉中的内容
Next
.Sections(1).Range.Select
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader '插入水印前需更改视图样式为页眉视图
Dim i As Integer
For i = 1 To 3
'设置插入水印,语法:表达式.AddTextEffect(预设文字效果, 文字内容, 字体名, 字体大小, 是否粗体, 是否斜体, 左侧位置, 顶部位置)
app.Selection.HeaderFooter.Shapes.AddTextEffect(10, "Foxtable 2016 ","宋体", 36, False, False, 0,i*200).Select
Next
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument '恢复视图样式到原来样式
End With
doc.save
app.quit
catch ex As exception
app.quit
msgbox(ex.message)
End try
[此贴子已经被作者于2016/9/8 18:00:48编辑过]