作者:绿色风
分类:
时间:2022-08-18
浏览:137
楼主 wjc2090742 |
Q:如何将指定文件夹中txt文件中每个数字后加1个空格? A:代码如下,利用word的查找替换可以使用通配符的特性:- Sub text()
- Dim fd As FileDialog
- Dim fdPath As String
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- If fd.Show = -1 Then
- fdPath = fd.SelectedItems(1)
- Else
- fdPath = "": MsgBox "未选择任何文件夹"
- End If
- Set fd = Nothing
-
- Dim fs As Object
- Dim fstxt As Object
- Set fs = CreateObject("scripting.filesystemobject")
- For Each fstxt In fs.getfolder(fdPath & "\").Files
- If fstxt.Name Like "*.txt" And Not fstxt.Name Like "*空格" Then
- Documents.Open FileName:=fdPath & "\" & fstxt.Name
- With ActiveDocument
- With .Content.Find
- .text = "([0-9])"
- .Replacement.text = "\1 "
- .Forward = True
- .Wrap = wdFindContinue
- .MatchWildcards = True
- .Execute Replace:=wdReplaceAll
- End With
- .SaveAs2 FileName:=fdPath & "\" & Replace(fstxt.Name, ".txt", "-空格.txt"), FileFormat:=wdFormatText, Encoding:=936, LineEnding:=wdCRLF
- .Close
- End With
- End If
- Next
- Set fs = Nothing
- Set fstxt = Nothing
- End Sub
Doc1.rar |
2楼 eliane_lei |
进来学习 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一