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 @   镜花缘  阅读(140)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
点击右上角即可分享
微信分享提示