利用VBA设置Word文档的页面布局.doc_第1页
利用VBA设置Word文档的页面布局.doc_第2页
利用VBA设置Word文档的页面布局.doc_第3页
利用VBA设置Word文档的页面布局.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

利用VBA设置Word文档的页面布局或者:代码:l 当前文档的页面设置Sub glkCurrentDocPageSetup() Dim glkDoc As Document 定义变量 Set glkDoc = Application.ActiveDocument 设置为当前文档 With glkDoc 设置文档参数 With .PageSetup 设置【页面设置】参数 .Orientation = wdOrientPortrait 页面方向:wdOrientPortrait-纵向,wdOrientLandscape-横向 .PageWidth = CentimetersToPoints(21) 纸张宽21cm .PageHeight = CentimetersToPoints(29.7) 纸张高29.7cm .TopMargin = CentimetersToPoints(2) 上边距2cm .BottomMargin = CentimetersToPoints(1.5) 下边距1.5cm .LeftMargin = CentimetersToPoints(2.5) 左边距2.5cm .RightMargin = CentimetersToPoints(1.5) 右边距1.5cm .HeaderDistance = CentimetersToPoints(0.5) 页眉0.5cm .FooterDistance = CentimetersToPoints(0.5) 页脚0.5cm End With 结束【页面设置】参数设置 .Save 保存文档参数 End With 结束文档参数设置End Subl 选择文档的页面设置Sub glkSelectDocPageSetup() Dim glkFileDialog As FileDialog 定义选择文件对话框 Dim glkSelectedItem As Variant 定义变量 Dim glkDoc As Document 定义文档 Set glkFileDialog = Application.FileDialog(msoFileDialogFilePicker) 设置变量 With glkFileDialog 设置对话框属性 .Filters.Clear 清除过滤器 .Filters.Add 所有 WORD 文件, *.Doc, 1 添加过滤条件 .AllowMultiSelect = True 允许多选 If .Show = -1 Then 如果按【打开】 Application.ScreenUpdating = False 关闭屏幕更新 For Each glkSelectedItem In .SelectedItems For-Next循环 Set glkDoc = Documents.Open(FileName:=glkSelectedItem, Visible:=False) 后台打开所选文档 With glkDoc 设置文档参数 With .PageSetup 设置【页面设置】参数 .Orientation = wdOrientPortrait 页面方向:wdOrientPortrait-纵向,wdOrientLandscape-横向 .PageWidth = CentimetersToPoints(21) 纸张宽21cm .PageHeight = CentimetersToPoints(29.7) 纸张高29.7cm .TopMargin = CentimetersToPoints(2) 上边距2cm .BottomMargin = CentimetersToPoints(1.5) 下边距1.5cm .LeftMargin = CentimetersToPoints(2.5) 左边距2.5cm .RightMargin = CentimetersToPoints(1.5) 右边距1.5cm .HeaderDistance = CentimetersToPoints(0.5) 页眉0.5cm .FooterDistance = CentimetersToPoints(0.5) 页脚0.5cm End With 结束【页面设置】参数设置 .Save 保存文档参数 End With 结束文档参数设置 glkDoc.Close 关闭文档 Next Application.ScreenUpdating = True 启用屏幕更新 MsgBox 所选文档的页面已设置完毕!, vbInformation Else 如果按【取消】 MsgBox 您取消了本次操作!, vbInformation End If End With备用资料: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 = FalseFor Each vrtSelectedItem In .SelectedItems 在所有选取项目中循环Set Doc = Documents.Open(FileName:=vrtSelectedItem, Visible:=False)With DocWith .PageSetup 进行页面设置.Orientation = wdOrientPortrait 页面方向为纵向.TopMargin = CentimetersToPoints(2.2) 上边距为2.2cm.BottomMargin = CentimetersToPoints(2.2) 下边距为2.2cm.LeftMargin = CentimetersToPoints(2.5) 左边距为2.5cm.RightMargin = CentimetersToPoints(2.5) 右边距为2.5com.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 WithWith .Content.ParagraphFormat 段落格式设置.LeftIndent = CentimetersToPoints(0) 左缩进0cm.RightIndent = CentimetersToPoints(0) 右缩进0cm.SpaceBefore = 0 段前间距0cm.SpaceBeforeAuto = False 段前间距不设为“自动”.SpaceAfter = 0 段后间距0cm.SpaceAfterAuto = False 段后间距不设为“自动”.LineSpacingRule = wdLineSpaceExactly.LineSpacing = 24 行距24磅.Alignment = wdAlignParagraphJustify 段落设置为两端对齐.WidowControl = False 不勾选“孤行控制”.KeepWithNext = False 不勾选“与下段同页”.KeepTogether = False 不勾选“段中不分页”.PageBreakBefore = False 不勾选“段前同页”.NoLineNumber = False 不勾选“取消行号”.Hyphenation = True 不勾选“允许西文在单词中间换行”.FirstLineIndent = CentimetersToPoints(0) 首行缩进0cm.OutlineLevel = wdOutlineLevelBodyText 大纲级别为“正文文本”.CharacterUnitLeftIndent = 0 段落左缩进0cm.CharacterUnitRightIndent = 0 段落右缩进0cm.CharacterUnitFirstLineIndent = 0 特殊格式为“无”.LineUnitBefore = 0 段前间距为0.LineUnitAfter = 0 段后间距为0.AutoAdjustRightIndent = True 自动调整段落的右缩进.DisableLineHeightGrid = False 勾选“如果定义了文档网格,则对齐网格”,即指定段落中的字符与行网格对齐.FarEastLineBreakControl = True 将东亚语言文字的换行规则应用于指定的段落.WordWrap = True 在指定段落或文本框的西文单词中间断字换行.HangingPunctuation = True 指定段落中的标点将可以溢出边界.HalfWidthPunctuationOnTopOfLine = False.AddSpaceBetweenFarEastAndAlpha = True 自动在指定段落的中文文字和拉丁文字之间添加空格。.AddSpaceBetweenFarEastAndDigit = True 自动在指定段落中的中文文字与数字之间添加空格.BaseLineAlignment = wdBaselineAlignAuto 自动调整基线字体对齐方式End With新增部分With .ContentWith .Font.NameFarEast = 宋体.Na

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论