VBA设置文档格式

Sub FormatDocument()
    
    ' 设置整个文档的字体、大小、颜色
    ActiveDocument.Select: Selection.ClearFormatting '文档格式清除
    ActiveDocument.Content.Font.Name = "宋体"
    ActiveDocument.Content.Font.Size = 12
    ActiveDocument.Content.Font.ColorIndex = wdBlack '黑色
    
    ' 设置整个文档的行距
    ActiveDocument.Content.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
    
    ' 设置整个文档的页边距
    ActiveDocument.PageSetup.TopMargin = CentimetersToPoints(1.27)
    ActiveDocument.PageSetup.BottomMargin = CentimetersToPoints(1.27)
    ActiveDocument.PageSetup.LeftMargin = CentimetersToPoints(1.27)
    ActiveDocument.PageSetup.RightMargin = CentimetersToPoints(1.27)
    ActiveDocument.PageSetup.PageWidth = CentimetersToPoints(21)   '页面宽度
    ActiveDocument.PageSetup.PageHeight = CentimetersToPoints(29.7)  '页面高度
    
    ' 设置页面方向
    'ActiveDocument.PageSetup.Orientation = wdOrientLandscape   '横向
    ActiveDocument.PageSetup.Orientation = wdOrientPortrait     '竖向
    
    ' 设置文档的页眉和页脚
    ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = " "
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = " "
    ActiveDocument.PageSetup.HeaderDistance = 22.677166
    ActiveDocument.PageSetup.FooterDistance = 22.677166
    ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone '删除页眉横线
    
    '插入页码
    ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Select

End Sub

posted @   镜花缘  阅读(142)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示