1、Attribute VB_Name = “AutoType“Sub perfect()WORD自动排版并打印,楷体、正文分栏。页面设置部分,上下边距0.5cm,左右边距1cm,无页眉页脚,横排!With ActiveDocument.PageSetup.LineNumbering.Active = False.Orientation = wdOrientLandscape.TopMargin = CentimetersToPoints(0.5).BottomMargin = CentimetersToPoints(0.5).LeftMargin = CentimetersToPoints(1)
2、.RightMargin = CentimetersToPoints(1).Gutter = CentimetersToPoints(0).HeaderDistance = CentimetersToPoints(0).FooterDistance = CentimetersToPoints(0).PageWidth = CentimetersToPoints(29.7).PageHeight = CentimetersToPoints(21).FirstPageTray = wdPrinterDefaultBin.OtherPagesTray = wdPrinterDefaultBin.Se
3、ctionStart = wdSectionNewPage.OddAndEvenPagesHeaderFooter = False.DifferentFirstPageHeaderFooter = False.VerticalAlignment = wdAlignVerticalTop.SuppressEndnotes = False.MirrorMargins = False.TwoPagesOnOne = False.BookFoldPrinting = False.BookFoldRevPrinting = False.BookFoldPrintingSheets = 1.GutterP
4、os = wdGutterPosLeft.LayoutMode = wdLayoutModeLineGridEnd WithApplication.Run MacroName:=“space“Application.Run MacroName:=“enter“ctrl+Home使光标回归至首字符处(即标题前)Selection.HomeKey Unit:=wdStoryctrl+Shift+使首段选中,目的是设置标题格式!Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtendIf Selection.Text = “ +
5、 vbCr Then Selection.Text = GetName + vbCrLf以下为段落格式,字体楷体,字号小二,加粗,居中对齐Selection.Font.Name = “楷体_GB2312“Selection.Font.Size = 18Selection.Font.Bold = wdToggleSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter使选中取消并移至下一段首。Selection.MoveRight Unit:=wdCharacter, Count:=1回车,目的是使正文分栏时行文美观!Selecti
6、on.TypeParagraphctrl+Shift+End使正文选中,目的是设置正文格式!Selection.EndKey Unit:=wdStory, Extend:=wdExtendApplication.Run MacroName:=“adjust“调整图片、表格的宽度正文楷体,三号Selection.Font.Name = “楷体_GB2312“Selection.Font.Name = “Times New Roman“Selection.Font.Size = 16段落格式首行缩进!With Selection.ParagraphFormat.LeftIndent = Centi
7、metersToPoints(0).RightIndent = CentimetersToPoints(0).SpaceBefore = 0.SpaceBeforeAuto = False.SpaceAfter = 0.SpaceAfterAuto = False.LineSpacingRule = wdLineSpaceSingle.Alignment = wdAlignParagraphJustify.WidowControl = False.KeepWithNext = False.KeepTogether = False.PageBreakBefore = False.NoLineNu
8、mber = False.Hyphenation = True.FirstLineIndent = CentimetersToPoints(0.35).OutlineLevel = wdOutlineLevelBodyText.CharacterUnitLeftIndent = 0.CharacterUnitRightIndent = 0.CharacterUnitFirstLineIndent = 2.LineUnitBefore = 0.LineUnitAfter = 0.AutoAdjustRightIndent = True.DisableLineHeightGrid = False.
9、FarEastLineBreakControl = True.WordWrap = True.HangingPunctuation = True.HalfWidthPunctuationOnTopOfLine = False.AddSpaceBetweenFarEastAndAlpha = True.AddSpaceBetweenFarEastAndDigit = True.BaseLineAlignment = wdBaselineAlignAutoEnd WithIf ActiveWindow.View.SplitSpecial wdPrintView ThenActiveWindow.A
10、ctivePane.View.Type = wdPrintViewEnd IfActiveDocument.Range(Start:=Selection.Start, End:=Selection.Start). _InsertBreak Type:=wdSectionBreakContinuousSelection.Start = Selection.Start + 1正文分为2栏,栏间有分隔线!With Selection.PageSetup.TextColumns.SetCount NumColumns:=2.EvenlySpaced = True.LineBetween = True.
11、Width = CentimetersToPoints(13.47).Spacing = CentimetersToPoints(0.75)End With返回文章开头Selection.HomeKey Unit:=wdStoryctrl+Shift+使首段选中,目的是设置标题为文档的文件名!Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtendSelection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend取消对回车符的选中新建变量,存储文件名,即首段中不
12、包含换行符的部分!Dim temptemp = GetNameIf Not (Selection.Type = 7 Or Trim(Selection.Text) = “) Thentemp = Trim(Replace(Selection.Text, “:“, “:“)End If设置保存路径,此处设为桌面处!ChangeFileOpenDirectory “r:“文件名为temp中的字符串ActiveDocument.SaveAs FileName:=temp + “.doc“, FileFormat:=wdFormatDocumentActiveDocument.PrintOutEnd
13、SubSub space()去除多余的空格(连续2个空格的情形)Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = “ “.Replacement.Text = “.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSounds
14、Like = False.MatchAllWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllSelection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = “ “.Replacement.Text = “ “.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord
15、 = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllSelection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = “ “.Replacement.Text = “ “.Forward = True.Wrap = wd
16、FindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd SubSub enter()清除连续2个的回车,避免出现太多的空白Selection.Find.ClearFormattingSelection.Find.Replacem
17、ent.ClearFormattingWith Selection.Find.Text = “pp“.Replacement.Text = “p“.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = False.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdR
18、eplaceAllSelection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = “pp“.Replacement.Text = “p“.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = False.MatchWildcards = False.MatchSoundsLike = False.MatchA
19、llWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllSelection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = “pp“.Replacement.Text = “p“.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte
20、 = False.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd SubSub adjust()设置所有图片宽度,未完成!For i = 1 To Selection.InlineShapes.CountSelection.InlineShapes(i).LockAspectRatio = msoTrueSelection.InlineShapes(i).Width = 360#NextF
21、or i = 1 To Selection.Tables.CountSelection.Tables(i).PreferredWidth = CentimetersToPoints(12.7)Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenterNextEnd SubFunction GetName()返回当前的中文日期和时间Dim y, m, d, h, mm, s, rRandomizey = Year(Now)m = Month(Now)If m 10 Then m = “0“ & md = Day(Now)If d 1
22、0 Then d = “0“ & dh = Hour(Now)If h 10 Then h = “0“ & hmm = Minute(Now)If mm 10 Then mm = “0“ & mms = Second(Now)If s 10 Then s = “0“ & sr = CInt(Rnd() * 10)If r 10 Then r = “0“ & rGetName = y & m & d & h & mm & s & rGetName = y & “年“ & m & “月“ & d & “日“ & h & “时“ & mm & “分“ & s & “秒“GetName = y + m + d + h + mm + s + r该语句不对,注意!GetName=y&m&d&h&mm&s&r不对,须有空格a = y + m + d + h + mm + s + rMsgBox (a)显示2117a = “eee“ + “www“MsgBox (a)显示eeewwwEnd Function