word vba遍历文件,打开另外word修改保存
2015-10-24 17:29
585 查看
处理完数个word,回头一看,才发现前面代码把一个符号搞反了。。。
把大于等于与小于等于两符号,颠倒了位置。。。晕。
马上用vba处理一下。
把这些word放在D盘根目录。逐个遍历并打开,逐一修改保存退出。OK!
代码如下:
把大于等于与小于等于两符号,颠倒了位置。。。晕。
马上用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 Loop End 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 Loop End Sub
相关文章推荐
- 后缀名m3u8文件转为一个ts文件---利用word vba
- 《关于VirtualBox在桥接模式下无法联网 解决方案》
- Vbs脚本经典教材
- 5、WPF 4.5 in VB 界面切换
- AB是一家?VAO与VBO
- 浅谈VB.NET
- 【VBA研究】取整函数的使用
- vb.net 2012 使用prodave6.2
- 【VB.NET】视频总结
- VB反编译研究[转]
- VC VB OCX传递参数郁闷记
- VB错误处理机制
- 【用EXCEL VBA控制IE】 2-1:EXCEL VBA对IE控制的基本操作-用IE访问某URL
- VB动态添加WebBrowser控件,并拦截弹出窗口(不用引用任何组件)
- VB ICO图表文件无效修正
- DVB机顶盒的概念与分类
- Filter/replace - VBA
- bat vbs后台运行
- VBI数据广播
- VBS中传值与传址的区别