使用前,需要在word内插入一个textbox1和一个commandbutton1,然后去掉文档中的标点符号。笔者比较懒,未加入剔除标点的代码。理论上下述代码可以统计999个字符(含标点)的文本,如需增加文本数量,则只需要增加数组体积即可。代码只是通过比较简单的for ,do循环实现,没啥技术含量哈。Sub Button1_click()'统计词频 Dim input_word As String Dim input_word_part(1 To 9999) As String Dim output_word_part(1 To 9999) As String Dim temp_inpu...
Word VBA自动排版- 通过For循环批量替换代码比较简单,只是在替换的基础上增加了最基础的For循环,有效节省了批量替换文本的时间。废话不多说,直接上代码,Ori = Array("a","b","c") '被替换文本Rep = Array("a","b","c") '替换后的文本For i = 0 To UBound(Ori) With Selection.find .Text = Ori(i) .Replacement.Text = Rep(i) .Forward = True .Wrap = wdFindContinue ...
Application对象(301) Application.ActivePrinter ‘获取当前打印机(302) Application.Height '当前应用程序文档的高度(303) Application.Width ‘当前应用程序文档的宽度(304) Application.Build ‘获取Word版本号和编译序号(305) Application.Caption ‘当前应用程序名(306) Application.DefaultSaveFormat '返回空字符串,表示Word文档(307) Application.DisplayRecentFiles '返回是否显示最近...
word vba宏在活动内容后插入文字Sub InsertTextAtEndOfDocument()ActiveDocument.Content.InsertAfter Text:="你好 www.txttool.com "End Subword vba宏在所选内容前插入文字Sub AddTextBeforeSelection()Selection.InsertBefore Text:="你好 www.txttool.com"End SubRange对象或 Selection对象在使用了 InsertBefore 或 InsertAfter方法之后...
word vba宏在所选内容前插入文字Sub AddTextBeforeSelection()Selection.InsertBefore Text:="你好 www.txttool.com"End Subword vba宏在所选内容后插入文字Sub InsertTextAtEndOfDocument()ActiveDocument.Content.InsertAfter Text:="你好 www.txttool.com "End SubRange对象或 Selection对象在使用了 InsertBefore 或 InsertAfter方法之后...
Sub 删除关键字字符之后的所有内容()Selection.Find.ClearFormattingWith Selection.Find .Text = "中国人" '关键字保留 .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute range1 = Selection.End Selection.Find.Execute range2 = Selection.Start ActiveDocument.Range(range1).Delete 'Activ...
Sub 删除关键字字符之后的所有内容关键字不保留()Selection.Find.ClearFormattingWith Selection.Find .Text = "中国人" '关键字不保留 .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute range1 = Selection.End Selection.Find.Execute range2 = Selection.Start ActiveDocument.Range(range2).Delete...
Sub 全角转换为半角()'使用前需先选中要替换的区域 Dim fullshape, halfshape As String, i As Integer '定义fullshape(全角)、halfshape(半角)为字符串型,i为整数型 fullshape = "A、B、C、D、" halfshape = "A.B.C.D." For i = 1 To 10 '循环10次 With Selection.Find .Text = Mid(fullshape, i, 1) 'mid函数:返回文本字符串中从指定位置开始的特定数目的字符,每次取一个标点符号...
Sub Macro字符串替换() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "讨论" .Replacement.Text = "研讨"End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub
Sub ChaFontName()With ActiveDocument.Content.Find.ClearFormatting.Font.Name = "Times New Roman" '查找宋体'.Font.Size = "小四"With .Replacement.ClearFormatting.Font.Name = "宋体" '替换成楷体.Font.Size = "10"End With.Execute FindText:="A", ReplaceWith:="A", Format:=True, Replace:=wdReplaceAllEnd WithEnd...