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
相关文章:
- word:设置基偶页不同和页眉页脚 2021-11-16
- Word分节符设置与不同页眉页脚页码设置 2022-01-02
- 将页眉和页脚设置为首页不同或奇偶页不同 - vincenzo.lai 2022-01-07
- word中页码设置问题?如果设置不同的页码? 2021-12-09
- 对不同角色用户设置不同的系统首页 2021-07-02
- 同一篇Word文档设置多个不同的页眉页脚 2021-11-16