您好,欢迎访问三七文档
Word宏小代码'1.-------------------------------------------------------------------------------------Sub粘贴无格式文本()Selection.PasteAndFormat(wdFormatPlainText)EndSub'2.-------------------------------------------------------------------------------------Sub删除空白行()DimiAsParagraph,nAsLongApplication.ScreenUpdating=False'关闭屏幕刷新ForEachiInActiveDocument.Paragraphs'在活动文档的段落集合中循环IfLen(i.Range)=1Then'判断段落长段,此处可根据文档实际情况i.Range.Delete'进行必要的修改可将任意长度段落删除n=n+1'计数EndIfNextMsgBox共删除空白段落&n&个!Application.ScreenUpdating=True'恢复屏幕刷新EndSubSub去掉空白行()Selection.HomeKeyUnit:=wdStorySelection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSelection.Find.Text=[^11^13]{2,}.Replacement.Text=^13.Forward=True.Wrap=wdFindContinue.Format=False.MatchCase=False.MatchWholeWord=False.MatchByte=False.MatchAllWordForms=False.MatchSoundsLike=False.MatchWildcards=TrueEndWithSelection.Find.ExecuteReplace:=wdReplaceAllApplication.GoBackEndSub'3.-------------------------------------------------------------------------------------Sub查找替换()WithActiveDocument.Content.Find.ClearFormatting'清除格式设置.Font.Name=新宋体'查找的字体格式With.Replacement'替换条件.ClearFormatting'清除格式设置.Font.Name=黑体'替换成黑体EndWith.Executefindtext:=,ReplaceWith:=,Format:=True,_Replace:=wdReplaceAll'是格式替换,全部替换EndWithEndSub'4.-------------------------------------------------------------------------------------Sub按日期保存()DimmypathAsString'假设新文档默认保存路径为F:\Test下以当前年月6位数字命名的子文件夹mypath=F:\&VBA.Format(Date,yyyymm)IfDir(mypath,vbDirectory)=ThenVBA.MkDirmypathWithDialogs(wdDialogFileSummaryInfo).Title=Format(Date,yyyymmdd).ExecuteEndWithActiveDocument.SaveAsmypath&\&VBA.Format(Date,yyyymmdd)&.docEndSub'5.-------------------------------------------------------------------------------------Sub页码()IfActiveWindow.View.SplitSpecialwdPaneNoneThenActiveWindow.Panes(2).CloseEndIfIfActiveWindow.ActivePane.View.Type=wdNormalViewOrActiveWindow._ActivePane.View.Type=wdOutlineViewThenActiveWindow.ActivePane.View.Type=wdPrintViewEndIfActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeaderIfSelection.HeaderFooter.IsHeader=TrueThenActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageFooterElseActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeaderEndIfSelection.EndKeyUnit:=wdLine,Extend:=wdExtendSelection.Fields.AddRange:=Selection.Range,Type:=wdFieldPageSelection.HomeKeyUnit:=wdLine,Extend:=wdExtendSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Font.Size=14ActiveWindow.ActivePane.View.SeekView=wdSeekMainDocumentEndSub'6.-------------------------------------------------------------------------------------Sub提取域代码()DimmyRangeAsRange,myCodesAsStringSetmyRange=Selection.RangeWithmyRangeIf.Fields.Count=0ThenMsgBox您所选的内容中没有域代码!,vbInformationExitSubElse.Fields.Update.TextRetrievalMode.IncludeFieldCodes=True.TextRetrievalMode.IncludeHiddenText=TruemyCodes=.TextmyCodes=VBA.Replace(myCodes,Chr(19),{)myCodes=VBA.Replace(myCodes,Chr(21),}).SetRange.End,.End.InsertAftermyCodes'注意,{}是由Ctrl+F9组合键自动插入的域标志!&vbLf&域代码:&myCodes.Font.Name=Tahoma.Font.Size=11.CutEndIfEndWithEndSub'7.-------------------------------------------------------------------------------------自定义我的工具栏Sub总标()Selection.Style=ActiveDocument.Styles(标题)Selection.Font.Name=宋体Selection.Font.Size=22WithSelection.ParagraphFormat.LeftIndent=CentimetersToPoints(0).RightIndent=CentimetersToPoints(0).SpaceBefore=0.SpaceBeforeAuto=False.SpaceAfter=0.SpaceAfterAuto=False.LineSpacingRule=wdLineSpaceSingle.Alignment=wdAlignParagraphCenter.WidowControl=False.KeepWithNext=False.KeepTogether=False.PageBreakBefore=False.NoLineNumber=False.Hyphenation=True.FirstLineIndent=CentimetersToPoints(0).OutlineLevel=wdOutlineLevel1'大纲级别.CharacterUnitLeftIndent=0.CharacterUnitRightIndent=0.CharacterUnitFirstLineIndent=0.LineUnitBefore=0.LineUnitAfter=0.AutoAdjustRightIndent=True.DisableLineHeightGrid=False.FarEastLineBreakControl=True.WordWrap=True.HangingPunctuation=True.HalfWidthPunctuationOnTopOfLine=False.AddSpaceBetweenFarEastAndAlpha=True.AddSpaceBetweenFarEastAndDigit=True.BaseLineAlignment=wdBaselineAlignAutoEndWithEndSubSub标1()Selection.Style=ActiveDocument.Styles(标题1)Selection.Font.Name=宋体Selection.Font.Size=16WithSelection.ParagraphFormat.LeftIndent=CentimetersToPoints(0).RightIndent=CentimetersToPoints(0).SpaceBefore=0.SpaceBeforeAuto=False.SpaceAfter=0.SpaceAfterAuto=False.LineSpacingRule=wdLineSpaceSingle.Alignment=wdAlignParagraphJustify.WidowControl=False.KeepWithNext=True.KeepTogether=True.PageBreakBefore=False.NoLineNumber=False.Hyphenation=True.FirstLineIndent=CentimetersToPoints(0.35).OutlineLevel=wdOutlineLevel1'大纲级别.CharacterUnitLeftIndent=0.CharacterUnitRightIndent=0.CharacterUnitFirstLineIndent=2.LineUnitBefore=0.LineUnitAfter=0.AutoAdjustRightIndent=True.DisableLineHeightGrid=False.FarEastLineBreakControl=True.WordWrap=True.HangingPunctuation=True.HalfWidthPunctuationOnTopOfLine=False.AddSpaceBetweenFarEastAndAlpha=True.AddSpaceBetweenFarEastAndDigit=True.BaseLineAlignment=wdBaselineAlignAutoEndWithEndSubSub标2()Selection.Style=ActiveD
本文标题:Word宏小代码
链接地址:https://www.777doc.com/doc-5517199 .html