• 批量格式设置word


    请参考:(请确保所需的文档在同一文件夹下)
    Sub 批量格式设置()  '此代码为指定文件夹中所有选取的WORD文件的进行格式设置
    Dim MyDialog As FileDialog, vrtSelectedItem As Variant, Doc As Document
    ' On Error Resume Next '忽略错误
    '定义一个文件夹选取对话框
    Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
    With MyDialog
    .Filters.Clear '清除所有文件筛选器中的项目
    .Filters.Add "所有 WORD 文件", "*.doc", 1 '增加筛选器的项目为所有WORD文件
    .AllowMultiSelect = True '允许多项选择
    If .Show = -1 Then '确定
    Application.ScreenUpdating = False
    For Each vrtSelectedItem In .SelectedItems '在所有选取项目中循环
    Set Doc = Documents.Open(FileName:=vrtSelectedItem, Visible:=False)
    With Doc
    With .PageSetup '进行页面设置
    .Orientation = wdOrientPortrait '页面方向为纵向
    .TopMargin = CentimetersToPoints(4.1) '上边距为4.1cm
    .BottomMargin = CentimetersToPoints(4.1) '下边距为4.1cm
    .LeftMargin = CentimetersToPoints(3.05) '左边距为3.05cm
    .RightMargin = CentimetersToPoints(3.05) '右边距为3.05com
    .Gutter = CentimetersToPoints(0) '装订线0cm
    .HeaderDistance = CentimetersToPoints(1.5)  '页眉1.5cm
    .FooterDistance = CentimetersToPoints(1.75) '页脚1.75cm
    .PageWidth = CentimetersToPoints(21) '纸张宽21cm
    .PageHeight = CentimetersToPoints(29.7) '纸张高29.7cm
    .SectionStart = wdSectionNewPage '节的起始位置:新建页
    .OddAndEvenPagesHeaderFooter = False '不勾选“奇偶页不同”
    .DifferentFirstPageHeaderFooter = False '不勾选“首页不同”
    .VerticalAlignment = wdAlignVerticalTop '页面垂直对齐方式为“顶端对齐”
    .SuppressEndnotes = False '不隐藏尾注
    .MirrorMargins = False '不设置首页的内外边距
    .BookFoldRevPrinting = False '不设置手动双面打印
    .BookFoldPrintingSheets = 1 '默认打印份数为1
    .GutterPos = wdGutterPosLeft '装订线位于左侧
    .LayoutMode = wdLayoutModeLineGrid '版式模式为“只指定行网格”
    End With
    .Close True
    End With
                Next
                Application.ScreenUpdating = True
            End If
        End With
        MsgBox "格式化文档操作设置完毕!", vbInformation
    End Sub

  • 相关阅读:
    MVC与MVVM
    js正则删除字符串中的部分内容(支持变量和特殊符号)
    小程序之rpx适配方案
    表单元素内容禁用拼写检查
    vue组件实例的生命周期
    Windows下生成目录结构树命令
    DRF之解析器源码解析
    restful规范快速记忆
    python报错之OSError
    xlrd、xlwt
  • 原文地址:https://www.cnblogs.com/Ellen/p/2073884.html
Copyright © 2020-2023  润新知