欢迎来到天天文库
浏览记录
ID:43483452
大小:129.26 KB
页数:6页
时间:2019-10-07
《2016Word宏代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Word宏小代码'1.-------------------------------------------------------------------------------------Sub无格式粘贴()'将剪贴板上的内容以"无格式文本"方式粘贴到当前位置。Selection.PasteAndFormat(wdFormatPlainText)EndSub'2.-------------------------------------------------------------------------------------Sub删除空白行()DimiAsParagraph,n
2、AsLongApplication.ScreenUpdating=False'关闭屏幕刷新ForEachiInActiveDocument.Paragraphs'在活动文档的段落集合中循环IfLen(i.Range)=1Then'判断段落长段,此处可根据文档实际情况i.Range.Delete'进行必要的修改可将任意长度段落删除n=n+1'计数EndIfNextMsgBox"共删除空白段落"&n&"个!"Application.ScreenUpdating=True'恢复屏幕刷新EndSubSub去掉空白行()Selection.HomeKeyUnit:=wdStorySelection
3、.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=TrueEndWithS
4、election.Find.ExecuteReplace:=wdReplaceAllApplication.GoBackEndSub'3.-------------------------------------------------------------------------------------Sub查找替换()WithActiveDocument.Content.Find.ClearFormatting'清除格式设置.Font.Name="新宋体"'查找的字体格式With.Replacement'替换条件.ClearFormatting'清除格式设置.Font.Name="
5、黑体"'替换成黑体EndWith.Executefindtext:="",ReplaceWith:="",Format:=True,_Replace:=wdReplaceAll'是格式替换,全部替换EndWithEndSub'4.-------------------------------------------------------------------------------------Sub按日期保存()DimmypathAsString'假设新文档默认保存路径为F:Test下以当前年月6位数字命名的子文件夹mypath="F:"&VBA.Format(Date,"yyy
6、ymm")IfDir(mypath,vbDirectory)=""ThenVBA.MkDirmypathWithDialogs(wdDialogFileSummaryInfo).Title=Format(Date,"yyyymmdd").ExecuteEndWithActiveDocument.SaveAsmypath&""&VBA.Format(Date,"yyyymmdd")&".doc"EndSub'5.-------------------------------------------------------------------------------------'去多行
7、,回车前带有空格的Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSelection.Find.Text="^p^w^p".Replacement.Text="^p".Forward=True.Wrap=wdFindContinue.Format=False.MatchCase=False.MatchWholeWord=False
此文档下载收益归作者所有