十万火急!请问如何在word里面用VBA代码添加页码?

MMICE 2014-04-30 02:25:50
需要可用好用的示例代码。
...全文
2573 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
MMICE 2014-04-30
  • 打赏
  • 举报
回复
多谢多谢
bcrun 2014-04-30
  • 打赏
  • 举报
回复
另外本论坛以前的这个帖子也可参考一下: http://bbs.csdn.net/topics/390265619 用VB给word页脚添加页码与内容 急急急急急急 [问题点数:100分,结帖人towgel]
bcrun 2014-04-30
  • 打赏
  • 举报
回复
虽说很多WORD功能的代码可以直接用录制宏方式得到,不过像这种稍微复杂些的显然没这么简单,而且还和版本有一定关系。我试过,在WORD2003中录制的在WORD2007中不能用,而在WORD2007中录制的本身就不能用,这类问题网上就有不少人问过。 不过还好我搜到网上这个帖子中网友整理的代码在两种版本中测试都有效,贴上来供参考: http://www.officefans.net/cdb/viewthread.php?tid=233567
Sub 插入页码()
'
'
    With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
     Set rng = .Range
     rng.Font.Size = 16
     rng.Font.Name = "Times New Roman"
     rng.Text = "— "
     rng.Collapse wdCollapseEnd
     ActiveDocument.Fields.Add rng, wdFieldEmpty, "Page"
     Set rng = .Range
     rng.Collapse wdCollapseEnd
     rng.Text = " —"
     .Range.Fields.Update
     .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
     End With
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    With Selection.ParagraphFormat
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        With .Borders
            .DistanceFromTop = 1
            .DistanceFromLeft = 4
            .DistanceFromBottom = 1
            .DistanceFromRight = 4
            .Shadow = False
        End With
    End With
    With Options
        .DefaultBorderLineStyle = wdLineStyleSingle
        .DefaultBorderLineWidth = wdLineWidth075pt
        .DefaultBorderColor = wdColorAutomatic
    End With
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧