一些Word快捷编辑特殊输入操作的域宏应用实例代码讲解.docx
- 文档编号:13554903
- 上传时间:2023-06-15
- 格式:DOCX
- 页数:10
- 大小:17.06KB
一些Word快捷编辑特殊输入操作的域宏应用实例代码讲解.docx
《一些Word快捷编辑特殊输入操作的域宏应用实例代码讲解.docx》由会员分享,可在线阅读,更多相关《一些Word快捷编辑特殊输入操作的域宏应用实例代码讲解.docx(10页珍藏版)》请在冰点文库上搜索。
一些Word快捷编辑特殊输入操作的域宏应用实例代码讲解
本文大部分代码来自于顾经宇《其实你还没懂word》及其网站或论坛,部分代码经过本人修改,对于方便应用word很有好处。
具体应用,请查看原书(右键点击用迅雷下载pdf版本。
发布于此,一为保留自用,二为共享他人。
标题中说是“域、宏应用实例代码”,实际上,把一些域的操作也编制成了宏,所以,以下全是宏代码。
至于word如何添加宏,不在本文叙述范围,请自行搜索网络。
1.打开文档时光标返回上次关闭时最后编辑处
SubAutoOpen(
'
'AutoOpenMacro宏名称一定要是AutoOpen(大小写无所谓
'宏在2008-4-16由*****创建
'
Application.GoBack
EndSub
2.无格式粘贴
Sub无格式粘贴(
'
'无格式粘贴Macro
'宏在2006-11-2由*****创建
Selection.PasteSpecialLink:
=False,DataType:
=wdPasteText,Placement:
=_
wdInLine,DisplayAsIcon:
=False
EndSub
3.匹配目标格式粘贴
Sub匹配目标格式粘贴(
'
'匹配目标格式粘贴Macro,这个宏的功能与上一个好像是一样的,虽然代码不同,都是匹配目标格式粘贴
'宏在2006-11-3由*****创建
'
Selection.PasteAndFormat(wdFormatSurroundingFormattingWithEmphasisEndSub
4.删除连续两个换行符
Sub删除连续两个换行符(
'
'删除连续两个换行符Macro
'宏在2006-11-2由*****创建
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormattingWithSelection.Find
.Text="^l^l"
.Replacement.Text=""
.Forward=True
.Wrap=wdFindAsk
.Format=False
.MatchCase=False
.MatchWholeWord=False
.MatchByte=True
.MatchWildcards=False
.MatchSoundsLike=False
.MatchAllWordForms=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAllSelection.MoveDownUnit:
=wdLine,Count:
=1EndSub
5.合并连续两个段落标记为一个
Sub替换连续两个段落标记为一个(
'
'替换连续两个段落标记为一个Macro
'宏在2006-11-2由*****创建
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormattingWithSelection.Find
.Text="^p^p"
.Replacement.Text="^p"
.Forward=True
.Wrap=wdFindAsk
.Format=False
.MatchCase=False
.MatchWholeWord=False
.MatchByte=True
.MatchWildcards=False
.MatchSoundsLike=False
.MatchAllWordForms=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAllSelection.MoveDownUnit:
=wdLine,Count:
=1EndSub
6.替换换行符为段落标记
Sub替换换行符为段落标记(
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormattingWithSelection.Find
.Text="^l"
.Replacement.Text="^p"
.Forward=True
.Wrap=wdFindAsk
.Format=False
.MatchCase=False
.MatchWholeWord=False
.MatchByte=True
.MatchWildcards=False
.MatchSoundsLike=False
.MatchAllWordForms=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAllSelection.MoveDownUnit:
=wdLine,Count:
=1EndSub
7.段前空半行
Sub段前空半行(
'
'段前空半行Macro
'宏在2006-11-3由*****创建
'
WithSelection.ParagraphFormat
.LineUnitBefore=0.5
EndWith
EndSub
8.段前空一行
Sub段前空一行(
'
'段前空一行Macro
'宏在2006-11-3由*****创建
'
WithSelection.ParagraphFormat
.LineUnitBefore=1
EndWith
EndSub
9.文献标号上标化
Sub文献标号上标化(
'
'参考文献上标化Macro
'宏在2006-11-3由*****创建
'
Selection.HomeKeyUnit:
=wdStory
Selection.Find.Replacement.ClearFormatting
WithSelection.Find.Replacement.Font
.Superscript=True
EndWith
WithSelection.Find
.Text="\[[0-9,0-9,~~-\-\]@\]"
.Replacement.Text=""
.MatchWildcards=True
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
Selection.Find.Replacement.ClearFormatting
WithSelection.Find.Replacement.Font
.Superscript=True
EndWith
WithSelection.Find
.Text="[[0-9,0-9,~~-\-\]@]"
.Replacement.Text=""
.MatchWildcards=True
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
10.箭头上方加文字
Sub箭头上方加文字(
'
'箭头上方加文字Macro
'宏在2008-4-16由*****创建
'
Selection.Fields.AddRange:
=Selection.Range,Type:
=wdFieldEmpty,_PreserveFormatting:
=False
Selection.TypeBackspace
Selection.DeleteUnit:
=wdCharacter,Count:
=1
Selection.TypeTextText:
="eq
\o(\s\do2(──────────→,\s\up5(敲击Delete键清除此段文字,改填所需文字,酌情增减箭头长度,最后同时按下shift和F9"
Selection.MoveLeftUnit:
=wdCharacter,Count:
=2
Selection.MoveLeftUnit:
=wdWord,Count:
=25,Extend:
=wdExtend‘顾
经宇的代码是26,改成25更好
EndSub
11.输入分式
Sub分式(
'
'公式Macro
'宏在2008-4-16由*****创建
'
Selection.Fields.AddRange:
=Selection.Range,Type:
=wdFieldEmpty,_PreserveFormatting:
=False
Selection.TypeBackspace
Selection.DeleteUnit:
=wdCharacter,Count:
=1
Selection.TypeTextText:
="eq\f(分子,分母"
EndSub
12.输入平均值
Sub平均值(
'
'平均值Macro没有在顾经宇的书和网站中找到这个宏,是本人录制编辑的
'宏在2008-4-17由*****创建
'
Selection.Fields.AddRange:
=Selection.Range,Type:
=wdFieldEmpty,_PreserveFormatting:
=False
Selection.TypeBackspace
Selection.DeleteUnit:
=wdCharacter,Count:
=1
Selection.TypeTextText:
="eq\o("
Selection.Font.Italic=wdToggle
Selection.TypeTextText:
="x"
Selection.Font.Italic=wdToggle
Selection.TypeTextText:
=",\s\do1("
Selection.InsertSymbolFont:
="宋体",CharacterNumber:
=175,Unicode:
=True
Selection.TypeTextText:
=""
EndSub
13.插入无空格的域
Sub插入域(
‘word的插入域命令,输入光标前后会有空格,有时候转换成域的结果时,后面的空格也会显示,这个宏会先删除掉空格再让你编辑域代码
'宏在2008-4-17由*****录制
'
Selection.Fields.AddRange:
=Selection.Range,Type:
=wdFieldEmpty,_PreserveFormatting:
=FalseSelection.TypeBackspaceSelection.DeleteUnit:
=wdCharacter,Count:
=1EndSub-------------------------------------------简单分割线----------------------------------------------个宏为添加使用参考文献提供方便以下5个宏为添加使用参考文献提供方便添加参考文献格式一,14.添加参考文献格式一,参考文献在文档末尾以1.2.3.格式排列Sub添加参考文献格式一(''添加参考文献Macro'宏在2008-4-17由*****创建'Selection.Style=ActiveDocument.Styles("尾注引用"Selection.TypeTextText:
="[]"Selection.MoveLeftUnit:
=wdCharacter,Count:
=1WithActiveDocument.Endnotes.StartingNumber=1.NumberStyle=wdNoteNumberStyleArabicEndWithActiveDocument.Endnotes.AddRange:
=Selection.Range,Reference:
=""Selection.MoveLeftUnit:
=wdCharacter,Count:
=1Selection.MoveLeftUnit:
=wdCharacter,Count:
=1,Extend:
=wdExtendSelection.Style=ActiveDocument.Styles("默认段落字体"Selection.MoveRightUnit:
=wdCharacter,Count:
=1Selection.DeleteUnit:
=wdCharacter,Count:
=1Selection.TypeTextText:
="."EndSub添加参考文献格式二参考文献在文档末尾以[1]式二,格式排列,15.添加参考文献格式二,参考文献在文档末尾以[1][2][3]格式排列,修改自格式一的代码Sub添加参考文献格式二(''添加参考文献Macro'宏在2008-4-17由*****创建'Selection.Style=ActiveDocument.Styles("尾注引用"Selection.TypeTextText:
="[]"Selection.MoveLeftUnit:
=wdCharacter,Count:
=1WithActiveDocument.Endnotes.StartingNumber=1.NumberStyle=wdNoteNumberStyleArabicEndWith
ActiveDocument.Endnotes.AddRange:
=Selection.Range,Reference:
=""Selection.MoveLeftUnit:
=wdCharacter,Count:
=1Selection.MoveLeftUnit:
=wdCharacter,Count:
=1,Extend:
=wdExtendSelection.Style=ActiveDocument.Styles("默认段落字体"Selection.MoveRightUnit:
=wdCharacter,Count:
=1Selection.DeleteUnit:
=wdCharacter,Count:
=1Selection.TypeTextText:
="]"Selection.MoveLeftUnit:
=wdCharacter+2,Count:
=1Selection.TypeTextText:
="["EndSub16.返回正文Sub返回正文('返回正文Macro'宏在2008-4-16由*****创建'IfActiveWindow.ActivePane.View.Type=wdPageViewOrActiveWindow._ActivePane.View.Type=wdOnlineViewOrActiveWindow.ActivePane.View.Type_=wdPrintPreviewThenActiveWindow.View.SeekView=wdSeekMainDocumentElseActiveWindow.Panes(2.CloseEndIfSelection.MoveRightUnit:
=wdCharacter,Count:
=2EndSub17.再次引用已有参考文献Sub引用编号('引用编号Macro'宏在2008-4-16由*****创建'Selection.Font.Superscript=wdToggleSelection.TypeTextText:
="[]"Selection.MoveLeftUnit:
=wdCharacter,Count:
=1WithDialogs(wdDialogInsertCrossReference.InsertAsHyperlink=True.ShowEndWithSelection.MoveRightUnit:
=wdCharacter,Count:
=1Selection.Font.Superscript=wdToggleEndSub查找被删参考文献遗留引用,18.查找被删参考文献遗留引用,
Sub查找被删编号('要删除某个参考文献,应该在原始引用处删除引用,这样可以一并删除参考文要删除某个参考文献,要删除某个参考文献应该在原始引用处删除引用,献,而不是在文档末尾文献列表处删除Selection.WholeStorySelection.Fields.UpdateSelection.Find.ClearFormattingWithSelection.Find.Text="错误!
未定义书签。
"EndWithSelection.Find.ExecuteSelection.MoveLeftUnit:
=wdCharacter,Count:
=1Selection.MoveRightUnit:
=wdCharacter,Count:
=1,Extend:
=wdExtendEndSub以上宏除第一个打开word文档自动运行之外,为了方便应用,建议自己编辑设置工具按钮,想用的时候点击即可,不需要繁琐的菜单、对话框寻找动作。
我自己设置的按钮如下图,从左至右,分别对应宏2-18。
至于如何把宏设置成按钮,请查看原书或搜索XX、google。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 一些 Word 快捷 编辑 特殊 输入 操作 应用 实例 代码 讲解