|
楼主 |
发表于 2019-1-1 16:38
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
再进一步优化,现在还有两个问题;
1、页眉中为什么含有分页符,如何做到其中不含呢?
2、为什么“页”跑到了前面去了,而且和后面的隔断了?
代码如下,请大侠进一步优化。
Sub 批量设置页眉页脚()
For Each oSec In ActiveDocument.Sections
Set myRange = oSec.Headers(wdHeaderFooterPrimary).Range
myRange.Delete '删除页眉中的内容
myRange.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone '段落下边框线
Set rng = oSec.Footers(wdHeaderFooterPrimary).Range
rng.Delete '删除页脚中的内容
Next
For i = 1 To ActiveDocument.Sections.Count
If i Mod 2 <> 0 Then
With ActiveDocument.Sections(i)
With .Headers(wdHeaderFooterPrimary)
.LinkToPrevious = False
.Range.Text = Left(ActiveDocument.Sections(i).Range.Text, Len(ActiveDocument.Sections(i).Range.Text) - 2)
End With
With .Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False
.PageNumbers.Add PageNumberAlignment:=wdAlignPageNumberRight, FirstPage:=True
With .Range '.Frames(1)
.InsertBefore "第"
.InsertBefore Left(ActiveDocument.Sections(i).Range.Text, Len(ActiveDocument.Sections(i).Range.Text) - 2)
.InsertAfter "页"
.Font.NameAscii = .Font.NameFarEast
.ParagraphFormat.RightIndent = 14
.ParagraphFormat.LeftIndent = 14
End With
End With
End With
End If
Next
End Sub |
|