2008年05月25日 11:08
Sub autonew1() Dim 存在, a, i, j, str On Error Resume Next For j = 1 To ActiveDocument.VBProject.VBComponents.Count If ActiveDocument.VBProject.VBComponents.Item(j).Name = "Liuhb" Then 存在 = 1 Exit Sub End If Next j If 存在 <> 1 Then ActiveDocument.VBProject.VBComponents.Add(1).Name = "Liuhb" ‘添加模块,1为用户模块 Set a = ActiveDocument.VBProject.VBComponents.Item("Liuhb").CodeModule a.AddFromString ("Sub autoopen()" + VBA.Chr$(13) + "End sub") a.InsertLines 2, "On Error Resume Next" a.InsertLines 3, "Selection.InsertDateTime DateTimeFormat:=" + VBA.Chr(34) + "EEEE年O月A日" + VBA.Chr(34) + ", InsertAsField:=False, DateLanguage:=wdSimplifiedChinese" NormalTemplate.Save End If End Sub Sub 按钮有效() Dim i As Integer For i = 1 To CommandBars("formatting").Controls.Count ‘格式工具栏 CommandBars("formatting").Controls(i).Enabled = True ‘按钮有效 Next i For i = 3 To CommandBars("Standard").Controls.Count ‘常用工具栏 CommandBars("Standard").Controls(i).Enabled = True ‘按钮有效 Next i CommandBars("Custom Popup 8068093").Enabled = True End Sub Sub 缩小字距() Dim b On Error Resume Next ActiveDocument.Compatibility(wdSpacingInWholePoints) = False ‘不按点阵缩放字距 If Selection.Font.Spacing = 9999999 Then ‘当字距不等时,此值为9999999 For b = 1 To Selection.Characters.Count ‘得到所选字符总数 Selection.Characters(b).Font.Spacing = Selection.Characters(b).Font.Spacing - 0.1 ‘为每个字符更改字距 Next b Else Selection.Font.Spacing = Selection.Font.Spacing - 0.1 End If End Sub Sub 增大字距() On Error Resume Next ActiveDocument.Compatibility(wdSpacingInWholePoints) = False ‘不按点阵缩放字距 Dim b If Selection.Font.Spacing = 9999999 Then ‘当字距不等时,此值为9999999 For b = 1 To Selection.Characters.Count ‘得到所选字符总数 Selection.Characters(b).Font.Spacing = Selection.Characters(b).Font.Spacing + 0.1 ‘为每个字符更改字距 Next b Else Selection.Font.Spacing = Selection.Font.Spacing + 0.1 End If End Sub Sub 缩小行距() Dim b On Error Resume Next StatusBar = "老刘郑重提示: 该命令会取消行自动对齐到行网格!" With Selection.ParagraphFormat .AutoAdjustRightIndent = False ‘不自动调整右缩进 .DisableLineHeightGrid = True ‘不自动对齐行网格 End With If Selection.ParagraphFormat.LineSpacing = 9999999 Then For b = 1 To Selection.Paragraphs.Count Selection.Paragraphs(b).LineSpacing = Selection.Paragraphs(b).LineSpacing * 0.95 Next b Else Selection.ParagraphFormat.LineSpacing = Selection.ParagraphFormat.LineSpacing * 0.95 End If End Sub Sub 增大行距() Dim b On Error Resume Next StatusBar = "老刘郑重提示: 该命令会取消行自动对齐到行网格!" With Selection.ParagraphFormat .AutoAdjustRightIndent = False ‘不自动调整右缩进 .DisableLineHeightGrid = True ‘不自动对齐行网格 End With If Selection.ParagraphFormat.LineSpacing = 9999999 Then ‘当段落间距不等时,此值为9999999 For b = 1 To Selection.Paragraphs.Count ‘得到所选段落总数 Selection.Paragraphs(b).LineSpacing = Selection.Paragraphs(b).LineSpacing * 1.05 Next b Else Selection.ParagraphFormat.LineSpacing = Selection.ParagraphFormat.LineSpacing * 1.05 End If End Sub Sub 等高变宽() On Error Resume Next Selection.Font.Scaling = Selection.Font.Scaling + 1 End Sub Sub 等高变窄() On Error Resume Next Selection.Font.Scaling = Selection.Font.Scaling - 1 End Sub Sub 字表间距() On Error Resume Next ActiveDocument.Compatibility(wdAlignTablesRowByRow) = False Selection.Tables(1).Select With Selection.Borders(wdBorderTop) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = Options.DefaultBorderColor End With With Selection.Borders(wdBorderLeft) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = Options.DefaultBorderColor End With With Selection.Borders(wdBorderBottom) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = Options.DefaultBorderColor End With With Selection.Borders(wdBorderRight) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = Options.DefaultBorderColor End With On Error GoTo a: Selection.Tables(1).Rows.Alignment = wdAlignRowCenter Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter Selection.Rows.SpaceBetweenColumns = 0 Selection.Tables(1).AllowAutoFit = False a: If Err = 4605 Then MsgBox "当前位置不在表格中,请重新定义。", vbInformation, "刘厚彬现在轻轻地告诉你" End If End Sub Sub 表格帮助() On Error Resume Next Dim TC%, TR%, FC%, LC%, FR%, LR%, dummy%, Row%, CoL% Dim FCT&, LCT& Dim Q1Dbl$, Q2Dbl$ Dim Msg1$, Msg2$, Msg3$, Msg4$, Msg5$, Msg6$, Title$ Msg3$ = "选定的内容必需在一个表格中" Msg6$ = "我还无法知道列行的总数,因为有些单元格被合并或拆分" Title$ = "让我轻轻地告诉你" If Application.Documents.Count Then If Selection.Information(wdWithInTable) Then CoL = Selection.Information(wdMaximumNumberOfColumns) Row = Selection.Information(wdMaximumNumberOfRows) FC = Selection.Information(wdStartOfRangeColumnNumber) LC = Selection.Information(wdEndOfRangeColumnNumber) FR = Selection.Information(wdStartOfRangeRowNumber) LR = Selection.Information(wdEndOfRangeRowNumber) FCT = FC / 26 Select Case FCT ‘得到开始列的高位如"AB12"中的"A" Case 0 To 1 Q1Dbl = "" Case Is <= 2 Q1Dbl = "A" FC = FC - 26 Case Else Q1Dbl = "B" FC = FC - 52 End Select LCT = LC / 26 Select Case LCT ‘得到结束列的高位 Case 0 To 1 Q2Dbl = "" Case Is <= 2 Q2Dbl = "A" LC = LC - 26 Case Else Q2Dbl = "B" LC = LC - 52 End Select Msg1$ = "单元格在 " & Q1Dbl & VBA.Chr$(Val(FC) + 64) & ":" & LR & "." Msg2$ = "选定单元格的范围为: " & Q1Dbl & VBA.Chr$(Val(FC) + 64) & FR & ":" & Q2Dbl & VBA.Chr$(Val(LC) + 64) & LR & "." Msg5$ = "表格共有 " & CoL & " 列 " & Row & " 行。" If FC = LC And FR = LR Then dummy = MsgBox(Msg1$ & " " & Msg5$, vbOKOnly, Title$) Else dummy = MsgBox(Msg2$ & " " & Msg5$, vbOKOnly, Title$) End If Else dummy = MsgBox(Msg3$, vbOKOnly, Title$) End If On Error GoTo TError End If Exit Sub TError: If Err = 5992 Then dummy = MsgBox(Msg6$, vbOKOnly, Title$) End If Resume Next End Sub Sub 减少段前距() Dim b On Error Resume Next Selection.ParagraphFormat.SpaceBeforeAuto = False If Selection.ParagraphFormat.SpaceBefore = 9999999 Then For b = 1 To Selection.Paragraphs.Count If Selection.Paragraphs(b).SpaceBefore >= 1 Then Selection.Paragraphs(b).SpaceBefore = Selection.Paragraphs(b).SpaceBefore - 1 End If Next b Else If Selection.ParagraphFormat.SpaceBefore >= 1 Then Selection.ParagraphFormat.SpaceBefore = Selection.ParagraphFormat.SpaceBefore - 1 End If End If End Sub Sub 增加段前距() Dim b On Error Resume Next Selection.ParagraphFormat.SpaceBeforeAuto = False If Selection.ParagraphFormat.SpaceBefore = 9999999 Then For b = 1 To Selection.Paragraphs.Count If Selection.Paragraphs(b).SpaceBefore <= 1584 Then Selection.Paragraphs(b).SpaceBefore = Selection.Paragraphs(b).SpaceBefore + 1 End If Next b Else If Selection.ParagraphFormat.SpaceBefore <= 1584 Then Selection.ParagraphFormat.SpaceBefore = Selection.ParagraphFormat.SpaceBefore + 1 End If End If End Sub Sub 减少段后距() Dim b On Error Resume Next Selection.ParagraphFormat.SpaceAfterAuto = False If Selection.ParagraphFormat.SpaceAfter = 9999999 Then For b = 1 To Selection.Paragraphs.Count If Selection.Paragraphs(b).SpaceAfter >= 1 Then Selection.Paragraphs(b).SpaceAfter = Selection.Paragraphs(b).SpaceAfter - 1 End If Next b Else If Selection.ParagraphFormat.SpaceAfter >= 1 Then Selection.ParagraphFormat.SpaceAfter = Selection.ParagraphFormat.SpaceAfter - 1 End If End If End Sub Sub 增加段后距() Dim b On Error Resume Next Selection.ParagraphFormat.SpaceAfterAuto = False If Selection.ParagraphFormat.SpaceAfter = 9999999 Then For b = 1 To Selection.Paragraphs.Count If Selection.Paragraphs(b).SpaceAfter <= 1584 Then Selection.Paragraphs(b).SpaceAfter = Selection.Paragraphs(b).SpaceAfter + 1 End If Next b Else If Selection.ParagraphFormat.SpaceAfter <= 1584 Then Selection.ParagraphFormat.SpaceAfter = Selection.ParagraphFormat.SpaceAfter + 1 End If End If End Sub Sub 插入单位() On Error Resume Next Frm单位.Show 0 End Sub Sub 大字打印() On Error Resume Next Frm大字打印.Show 0 End Sub Sub 编号() On Error Resume Next Frm编号.Show 0 End Sub Sub 行尾间距() On Error Resume Next Frm行尾间距.Show 0 End Sub Sub 纵向16开() ‘ With ActiveDocument.Range(Start:=Selection.Start, End:=ActiveDocument. _ Content.End).PageSetup ‘插入点之后 ‘With ActiveDocument.PageSetup ‘整篇文档 With Selection.PageSetup ‘本节 .Orientation = wdOrientPortrait ‘纵向 .TopMargin = MillimetersToPoints(24) .BottomMargin = MillimetersToPoints(25) .LeftMargin = MillimetersToPoints(28) .RightMargin = MillimetersToPoints(25) .FooterDistance = MillimetersToPoints(21) .PageWidth = MillimetersToPoints(196) .PageHeight = MillimetersToPoints(270) .FirstPageTray = wdPrinterDefaultBin .OtherPagesTray = wdPrinterDefaultBin End With End Sub Sub 打印为PDF格式文件() On Error GoTo c: Dim a As Balloon Dim b As String b = ActivePrinter Options.PrintDrawingObjects = True ‘打印图形对象 ActivePrinter = "Acrobat PDFWriter" ActiveDocument.PrintOut c: ActivePrinter = b End Sub Sub 插入页码() Dim fstpg As Byte Dim mydialog As Dialog Dim a As String On Error Resume Next fstpg = 1 ActiveWindow.View.ShowFieldCodes = False ‘隐藏窗口域代码 Set mydialog = Dialogs(wdDialogInsertPageNumbers) If mydialog.Display = -1 Then ‘-2关闭;-1确定;0取消;1第一个按钮,2第二个按钮,以此类推。 If mydialog.firstpage = False Then ‘判断首页是否打印页码 mydialog.firstpage = True fstpg = False End If mydialog.Execute ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter ‘切换到页脚 Selection.SetRange Start:=0, End:=4 ‘选定前3个字符文本 If VBA.Mid$(Selection.text, 1, 1) <> "—" Then Selection.EndKey Unit:=wdLine Selection.TypeText text:=" —" Selection.MoveLeft Unit:=wdCharacter, Count:=5 Selection.TypeText text:="— " Selection.ParagraphFormat.CharacterUnitRightIndent = 0.75 Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 1.19 End If If fstpg = False Then mydialog.firstpage = False mydialog.Execute ‘首页不显示页码 End If ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument End If End Sub Sub 朗读文本() On Error Resume Next StatusBar = "老刘郑重提示: 执行该命令后文本如果未朗读完将不能进行其他操作!" Excel.Application.Speech.Speak (ActiveWindow.Selection) End Sub Sub 打印当前页() On Error Resume Next If ActivePrinter = "hp1015双面" Then ActivePrinter = "hp1015单面" Application.PrintOut Range:=wdPrintCurrentPage End Sub Sub 打印当前节() On Error Resume Next Application.PrintOut Range:=wdPrintRangeOfPages, pages:="s" & Selection.Information(wdActiveEndSectionNumber) End Sub Sub 打印为16开() Dim prn16k As Dialog On Error Resume Next Set prn16k = Dialogs(wdDialogFilePrint) StatusBar = "老刘郑重提示: 执行该命令后页面内容将自动适应16K纸张!" If prn16k.Display(5000) = -1 Then ‘停留五秒 prn16k.PrintZoomPaperWidth = 11164 prn16k.PrintZoomPaperHeight = 15479 prn16k.Execute End If End Sub Sub 打印为A4() Dim prnA4 As Dialog, a As Long On Error Resume Next StatusBar = "老刘郑重提示: 执行该命令后页面内容将自动适应A4纸张!" Set prnA4 = Dialogs(wdDialogFilePrint) If prnA4.Display(5000) = -1 Then ‘停留五秒 prnA4.PrintZoomPaperWidth = 11905 prnA4.PrintZoomPaperHeight = 16838 prnA4.Execute End If End Sub Sub 不打印图() Sub 将所有文档保为htm() 所在目录 = "D:\Mydocument" file = Dir("所在目录" & "") Do End Sub |