版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Word宏代码集锦Word宏代码集锦1一、修改word格式:11、 智能清除选区软回车(换行符)12、 清除选区多余空段13、 合并选区中“,”结束的多余分段34、 清除选区单字节空格35、 清除选区单字节空格46、 清除选区1字空格47、 清除选区段首2字空格48、 清除选区Tab59、 增加选区空格510、 选区段首缩进0字511、 选区段首缩进:2字612、 选区段首缩进转空格已完美613、 选区段后间距1行714、 选区段后间距1行715、 选区段后间距1行716、 清除选区图片817、 选区硬回车转软回车818、 清除选区软回车819 合并选区段落920、 选区空格转硬回车921、
2、选区标点半角转全角1022、 选区标点全角转半角1123、 选区中文句号转半角1224、把文档第一段设置为标题1的格式1225、选中的文本横向居中1326、缩小字距1327、增大字距1428、缩小行距1429、增大行距1530、等高变宽1531、等高变窄1532、字表间距1633、纵向16开1634、插入页码1735、小写金额转大写金额18二、其它231.调整图片大小232.转字体243.转文件格式254、文件加密275、字符替换276、替换引号287、打印为PDF格式文件298、朗读文本299. 文献标号上标化2910. 箭头上方加文字3011 添加参考文献格式一,参考文献在文档末尾以1 2
3、 3 格式排列3012. 添加参考文献格式二,参考文献在文档末尾以1 2 3 格式排列,修改自格式一的代码3113. 返回正文3214. 再次引用已有参考文献3215. 查找被删参考文献遗留引用,3216、统计修订的字数3317、快速提取脚注内容3318、从任意页面编排页码3419、批量实现缩放打印3520、对文档内容进行顺序排列3621、替换Word文档插图的超链接3622、为文档的每页添加固定内容3723、批量实现图片的等比例缩37一、 修改word格式:1、 智能清除选区软回车(换行符)Sub 智能清除选区软回车() With Selection.Find .Text = ?l .Rep
4、lacement.Text = &p .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = 1l .Rep
5、lacement.Text = &p End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = l .Replacement.Text = End With Selection.Find.Execute Replace:=wdReplaceAll End Sub2、 清除选区多余空段Sub 清除选区多余空段() With Selection.Find .Text = pp .Replacement.Text = p .MatchWildcards = False End With Sele
6、ction.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ppp .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ppp .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplac
7、eAll With Selection.Find .Text = pp .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = pp .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ppp .
8、Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = p .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = pp .Replacement.Text = p .MatchWildcards =
9、False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = pp .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub3、 合并选区中“,”结束的多余分段Sub 合并选区多余分段() With Selection.Find .Text = ,p .Replacement.Text = , .MatchWildcards
10、= False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = 、p .Replacement.Text = 、 .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub4、 清除选区单字节空格Sub 清除选区单字节空格() With Selection.Find .Text = .Replacement.Text = .MatchWildcards = False E
11、nd With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub5、 清除选区单字节空格Sub 清除选区2单字节空格() With Selection.Find .Text = .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub6、 清除选区1字空格Sub 清除选区1字空格() With Selection.Find .Text = .Replacement.Text = .Match
12、Wildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub7、 清除选区段首2字空格Sub 清除选区段首2字空格() With Selection.Find .Text = .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub8、 清除选区TabSub 清除选区Tab() With Selection.Find .Text = vbTab .R
13、eplacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub9、 增加选区空格Sub 增加选区空格() With Selection.Find .Text = .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub10、 选区段首缩进0字Sub 选区段首无缩进()With Selection.Fin
14、d .Text = .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.ParagraphFormat .LeftIndent = CentimetersToPoints(0) 左缩进0字符 .RightIndent = CentimetersToPoints(0) 右缩进0字符 .FirstLineIndent = CentimetersToPoints(0) 首行缩进点0公分 .CharacterUnitLeftInd
15、ent = 0 左缩进单位0字符 .CharacterUnitRightIndent = 0 右缩进单位0字符 .CharacterUnitFirstLineIndent = 0 End With With Selection.ParagraphFormat .LeftIndent = CentimetersToPoints(0) 左缩进1字符 .RightIndent = CentimetersToPoints(0) 右缩进2字符 .FirstLineIndent = CentimetersToPoints(0) 首行缩进点0.35公分 .CharacterUnitLeftIndent =
16、0 左缩进单位0字符 .CharacterUnitRightIndent = 0 右缩进单位0字符 .CharacterUnitFirstLineIndent = 0 End WithEnd Sub11、 选区段首缩进:2字Sub 选区段首缩进2字() With Selection.ParagraphFormat .LeftIndent = CentimetersToPoints(0) 左缩进1字符 .RightIndent = CentimetersToPoints(0) 右缩进2字符 .FirstLineIndent = CentimetersToPoints(0.35) 首行缩进点单位公
17、分 .CharacterUnitLeftIndent = 0 左缩进单位0字符 .CharacterUnitRightIndent = 0 右缩进单位0字符 .CharacterUnitFirstLineIndent = 2 End With End Sub12、 选区段首缩进转空格已完美Sub 选区段首缩进转空格() Selection.InsertParagraphBefore Call 选区段首无缩进 With Selection.Find .Text = p .Replacement.Text = p .MatchWildcards = False End With Selection
18、.Find.Execute Replace:=wdReplaceAll Selection.Delete With Selection.Find .Text = p .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub13、 选区段后间距1行Sub 选区段后间距1行() Selection.ParagraphFormat.FirstLineIndent = CentimetersToPoints(0) Selection.Paragrap
19、hFormat.LineUnitAfter = 1 End Sub14、 选区段后间距1行 Sub 选区段前段后间距半行() Selection.ParagraphFormat.FirstLineIndent = CentimetersToPoints(0) Selection.ParagraphFormat.LineUnitBefore = 0.5 Selection.ParagraphFormat.LineUnitAfter = 0.5End Sub15、 选区段后间距1行Sub 选区段前段后无间距() Selection.ParagraphFormat.FirstLineIndent =
20、 CentimetersToPoints(0) Selection.ParagraphFormat.LineUnitBefore = 0 Selection.ParagraphFormat.LineUnitAfter = 0End Sub16、 清除选区图片Sub 清除选区图片() With Selection.Find .Text = 1 .Replacement.Text = .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub17、 选区硬回车转软回车Sub 选区硬回车转软
21、回车() With Selection.Find .Text = p .Replacement.Text = l .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub18、 清除选区软回车Sub 清除选区软回车() With Selection.Find .Text = l .Replacement.Text = .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll End Su
22、b19 合并选区段落Sub 合并选区段落() With Selection.Find .Text = .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = p .Replacement.Text = l .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .
23、Text = l .Replacement.Text = .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Paragraphs.Add 添加段落符号 End Sub20、 选区空格转硬回车Sub 选区空格转硬回车() With Selection.Find .Text = .Replacement.Text = p .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllE
24、nd Sub 21、 选区标点半角转全角Sub 选区标点半角转全角() With Selection.Find .Text = , .Replacement.Text = , .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ; .Replacement.Text = ; .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With
25、 Selection.Find .Text = : .Replacement.Text = : .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ? .Replacement.Text = ? .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ! .Replacement.T
26、ext = ! .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = . .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = . .Replacement.Text = 。 .MatchWildcards = False End With S
27、election.Find.Execute Replace:=wdReplaceAll End Sub22、 选区标点全角转半角 Sub 选区标点全角转半角() With Selection.Find .Text = , .Replacement.Text = , .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ; .Replacement.Text = ; .MatchWildcards = False End With Sele
28、ction.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = : .Replacement.Text = : .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ? .Replacement.Text = ? .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll
29、 With Selection.Find .Text = ! .Replacement.Text = ! .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = .Replacement.Text = . .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = 。 .Replacemen
30、t.Text = . .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub23、 选区中文句号转半角Sub 选区中文句号转半角() With Selection.Find .Text = 。 .Replacement.Text = . .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub24、把文档第一段设置为标题1的格式Sub 标题1() ActiveDocum
31、ent.Paragraphs(1).Style = ActiveDocument.Styles(标题 1) Selection.ParagraphFormat.Alignment = wdAlignParagraphCenterEnd Sub25、选中的文本横向居中Sub 横向居中()With Selection.Find .Text = .Replacement.Text = .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.ParagraphFormat
32、.LeftIndent = CentimetersToPoints(0) 左缩进0字符 .RightIndent = CentimetersToPoints(0) 右缩进0字符 .FirstLineIndent = CentimetersToPoints(0) 首行缩进点0公分 .CharacterUnitLeftIndent = 0 左缩进单位0字符 .CharacterUnitRightIndent = 0 右缩进单位0字符 .CharacterUnitFirstLineIndent = 0 End With With Selection.ParagraphFormat .LeftInde
33、nt = CentimetersToPoints(0) 左缩进1字符 .RightIndent = CentimetersToPoints(0) 右缩进2字符 .FirstLineIndent = CentimetersToPoints(0) 首行缩进点0.35公分 .CharacterUnitLeftIndent = 0 左缩进单位0字符 .CharacterUnitRightIndent = 0 右缩进单位0字符 .CharacterUnitFirstLineIndent = 0 End With Selection.ParagraphFormat.Alignment = wdAlignP
34、aragraphCenterEnd Sub26、缩小字距Sub 缩小字距() Dim b On Error Resume Next ActiveDocument.Compatibility(wdSpacingInWholePoints) = False 不按点阵缩放字距 If Selection.Font.Spacing = Then 当字距不等时,此值为 For b = 1 To Selection.Characters.Count 得到所选字符总数 Selection.Characters(b).Font.Spacing = Selection.Characters(b).Font.Spa
35、cing - 0.1 为每个字符更改字距 Next b Else Selection.Font.Spacing = Selection.Font.Spacing - 0.1 End IfEnd Sub27、增大字距Sub 增大字距() On Error Resume Next ActiveDocument.Compatibility(wdSpacingInWholePoints) = False 不按点阵缩放字距 Dim b If Selection.Font.Spacing = Then 当字距不等时,此值为 For b = 1 To Selection.Characters.Count 得
36、到所选字符总数 Selection.Characters(b).Font.Spacing = Selection.Characters(b).Font.Spacing + 0.1 为每个字符更改字距 Next b Else Selection.Font.Spacing = Selection.Font.Spacing + 0.1 End IfEnd Sub28、缩小行距Sub 缩小行距() Dim b On Error Resume Next StatusBar = 老刘郑重提示: 该命令会取消行自动对齐到行网格! With Selection.ParagraphFormat .AutoAdj
37、ustRightIndent = False 不自动调整右缩进 .DisableLineHeightGrid = True 不自动对齐行网格 End With If Selection.ParagraphFormat.LineSpacing = Then For b = 1 To Selection.Paragraphs.Count Selection.Paragraphs(b).LineSpacing = Selection.Paragraphs(b).LineSpacing * 0.95 Next b Else Selection.ParagraphFormat.LineSpacing =
38、 Selection.ParagraphFormat.LineSpacing * 0.95 End IfEnd Sub29、增大行距Sub 增大行距() Dim b On Error Resume Next StatusBar = 老刘郑重提示: 该命令会取消行自动对齐到行网格! With Selection.ParagraphFormat .AutoAdjustRightIndent = False 不自动调整右缩进 .DisableLineHeightGrid = True 不自动对齐行网格 End With If Selection.ParagraphFormat.LineSpacing
39、 = Then 当段落间距不等时,此值为 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 IfEnd Sub30、等高变宽Sub 等高变宽() On Error Resume Next
40、Selection.Font.Scaling = Selection.Font.Scaling + 1End Sub31、等高变窄Sub 等高变窄() On Error Resume Next Selection.Font.Scaling = Selection.Font.Scaling - 1End Sub32、字表间距Sub 字表间距() On Error Resume Next ActiveDocument.Compatibility(wdAlignTablesRowByRow) = False Selection.Tables(1).Select With Selection.Bord
41、ers(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(wdBorderBot
42、tom) .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.Ali
43、gnment = wdAlignRowCenter Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter Selection.Rows.SpaceBetweenColumns = 0 Selection.Tables(1).AllowAutoFit = Falsea: If Err = 4605 Then MsgBox 当前位置不在表格中,请重新定义。, vbInformation, 刘厚彬现在轻轻地告诉你 End IfEnd Sub33、纵向16开Sub 纵向16开() With ActiveDocument.Range(
44、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
45、= MillimetersToPoints(25) .FooterDistance = MillimetersToPoints(21) .PageWidth = MillimetersToPoints(196) .PageHeight = MillimetersToPoints(270) .FirstPageTray = wdPrinterDefaultBin .OtherPagesTray = wdPrinterDefaultBinEnd WithEnd Sub34、插入页码Sub 插入页码() Dim fstpg As Byte Dim mydialog As Dialog Dim a As String On Error Resume Next fstpg = 1 Acti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026浙江嘉兴市桐乡市凤鸣高中招聘寝室生活管理人员若干名备考题库及答案详解【网校专用】
- 2026年校服购买合同(1篇)
- 2026贵州贵阳贵安招聘中小学(幼儿园)教师819人备考题库附参考答案详解【典型题】
- 2026浙江温州桐君堂药材有限公司招聘营业员1人备考题库含完整答案详解【各地真题】
- 2026天津铁路建设投资控股(集团)有限公司招聘1人备考题库往年题考附答案详解
- 2026湖南长沙市芙蓉区招聘中小学教师41人备考题库及参考答案详解(轻巧夺冠)
- 2026江西昌华路建设咨询监理有限公司招聘备考题库学生专用附答案详解
- 中建一局西北公司2026届春季校园招聘备考题库附答案详解【夺分金卷】
- 2026年中国铁路国际有限公司校园招聘笔试备考试题及答案解析
- 2026年南京大数据集团有限公司校园招聘考试备考试题及答案解析
- 《产品三维建模与结构设计(UG)》技工全套教学课件
- 设备定期清理管理制度
- DB4401-T 215-2023 井盖设施技术规范
- 政治●湖北卷丨2024年湖北省普通高中学业水平选择性考试政治试卷及答案
- 语文●浙江卷丨2021年普通高等学校招生全国统一考试语文试卷及答案
- 中医脾的生理功能
- 5.3《阳燧照物》(课件)-【中职专用】高二语文(高教版2023拓展模块下册)
- 垃圾清运服务承诺方案
- 2025年国际关系与外交理论考试题目及答案
- 用电缴费合同协议
- 风电施工安全培训课件
评论
0/150
提交评论