axjl-w

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

分类:

技术点:

相关文章: