word vba遍历文件,打开另外word修改保存
来源:互联网 发布:期货套利 知乎 编辑:程序博客网 时间:2024/05/16 05:10
处理完数个word,回头一看,才发现前面代码把一个符号搞反了。。。
把大于等于与小于等于两符号,颠倒了位置。。。晕。
马上用vba处理一下。
把这些word放在D盘根目录。逐个遍历并打开,逐一修改保存退出。OK!
代码如下:
Sub a() Dim doc As Document, myFile As String Dim a As Range myFile = Dir("D:\" & "*.docx") Do While myFile <> "" myFile = "D:\" & myFile Set doc = Documents.Open(myFile) Set a = doc.Range Selection.WholeStory '展开域 Selection.Fields.ToggleShowCodes '≥≤ 把大换小,把小换小 a.Find.Execute FindText:="≤", MatchWildcards:=True, replacewith:="$", Replace:=wdReplaceAll a.Find.Execute FindText:="≥", MatchWildcards:=True, replacewith:="#", Replace:=wdReplaceAll a.Find.Execute FindText:="$", MatchWildcards:=True, replacewith:="≥", Replace:=wdReplaceAll a.Find.Execute FindText:="#", MatchWildcards:=True, replacewith:="≤", Replace:=wdReplaceAll Selection.WholeStory Selection.Fields.ToggleShowCodes '保存退出 doc.Save doc.Close Set doc = Nothing '查找下一个 myFile = Dir LoopEnd Sub
Sub a() Dim doc As Document, myFile As String Dim a As Range myFile = Dir("D:\" & "*.docx") Do While myFile <> "" myFile = "D:\" & myFile Set doc = Documents.Open(myFile) Set a = doc.Range Selection.WholeStory '展开域 Selection.Fields.ToggleShowCodes '域调整 a.Find.Execute FindText:="\s( ,", MatchWildcards:=False, replacewith:="\s\do6(", Replace:=wdReplaceAll a.Find.Execute FindText:="\s(", MatchWildcards:=False, replacewith:="\s\up7(", Replace:=wdReplaceAll Selection.WholeStory Selection.Fields.ToggleShowCodes Dim c As Range, strText As String '下标用域 For Each c In a.Characters If c.Font.Subscript = True Then c.Select strText = Replace(c.Text, Chr(13), "") If strText <> "" Then c.Delete Set myfield = Selection.Fields.Add(Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=True) '增加一个新域 myfield.Code.Text = "eq \s\do4(" & strText & ")" Else c.Font.Subscript = False End If End If Next '保存退出 doc.Save doc.Close Set doc = Nothing '查找下一个 myFile = Dir LoopEnd Sub
0 0
- word vba遍历文件,打开另外word修改保存
- 修改 WORD 命令 (VBA)
- word vba批量替换文件内容并批量修改文件名
- Mac OS X 下 Word VBA 宏 - 如何在 Word 里打开 Excel 文件
- Word VBA
- Word VBA
- 打开,保存文件(VBA)
- javascript打开word文件
- 修改只读word文件
- Word插入文件 VBA 合并 文件
- vba word 下载网络上的文件
- Word文件的保存类型
- word保存为pdf文件
- 富文本保存为Word时,打开Word为html
- word,excel宏遍历文件
- 网页里打开Word文件
- js打开word,exls文件
- js直接打开word文件
- Android样式与主题浅析
- MYsql查询高速缓存设置
- leetcode 19 Remove Nth Node from end of list
- android的消息处理机制
- C++网络编程学习指南
- word vba遍历文件,打开另外word修改保存
- 乱乱
- Java之网络爬虫WebCollector+selenium+phantomjs(一)
- OC类的三大特性:继承,封装和多态
- Python---类的"__new__"和"__init__"方法
- Array Programming Guide
- 51nod 1082 与7无关的数 (打表)
- sqlplus使用小技巧
- MFC下拉列表数据顺序乱排解决方法