|
楼主,你先把单个.rtf文档转换为.doc文档搞掂,然后,用我的——循环遍历文件夹_集成(宏)的第1个选项:键入 0,把单个.rtf转换为.doc文档的代码拷贝到 SingleDoc 宏中,屏蔽原来的旧代码,可以试试(请此前备份):
Sub 循环遍历文件夹_集成()
On Error Resume Next
Dim fd As FileDialog, i As Long, doc As Document, p As String, e As Long, j As String, s As Long, t As Long
If MsgBox("是否处理 Word 文档(*.doc)?(否则处理文本文档(*.txt))", vbYesNo + vbExclamation, "循环遍历文件夹_集成") = vbYes Then t = 0 Else t = 1
input_select:
j = InputBox("======请输入各个功能对应的数字!======" & vbCr & "0=示例代码(自定义)" & vbCr & "1=批量打印" & vbCr & "2=批量合并" & vbCr & "3=批量转换" & vbCr & "4=提取文件名", "循环遍历文件夹_集成", "1")
If j = "" Then Exit Sub
If j = 0 Then
e = 0
ElseIf j = 1 Then
e = 1
ElseIf j = 2 Then
Documents.Add
If MsgBox("合并文档之间是否插入分页符?", vbYesNo + vbExclamation, "循环遍历文件夹_集成") = vbYes Then s = 1 Else s = 0
e = 2
ElseIf j = 3 Then
e = 3
ElseIf j = 4 Then
Documents.Add
e = 4
Else
GoTo input_select
End If
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
Set fd = Nothing
If MsgBox("是否处理文件夹 " & p & "?", vbYesNo + vbExclamation, "循环遍历文件夹_集成") = vbNo Then Exit Sub
With Application.FileSearch
' .NewSearch
.LookIn = p
.SearchSubFolders = True
If t = 0 Then .FileName = "*.doc" Else .FileName = "*.txt"
' .FileType = msoFileTypeAllFiles
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
If e = 4 Then GoTo un_need
If t = 0 Then Set doc = Documents.Open(FileName:=.FoundFiles(i)) Else Set doc = Documents.Open(FileName:=.FoundFiles(i), Encoding:=936)
un_need:
If e = 0 Then
SingleDoc
ElseIf e = 1 Then
doc.PrintOut
doc.Close savechanges:=wdDoNotSaveChanges
ElseIf e = 2 Then
doc.Content.Copy
doc.Close
Selection.EndKey Unit:=wdStory
Selection.Paste
If s = 1 Then Selection.InsertBreak Type:=wdPageBreak
ElseIf e = 3 Then
If t = 0 Then doc.SaveAs FileName:=Left(doc.FullName, Len(doc.FullName) - 4) & ".txt", FileFormat:=wdFormatText Else doc.SaveAs FileName:=Left(doc.FullName, Len(doc.FullName) - 4) & ".doc", FileFormat:=wdFormatDocument
doc.Close
ElseIf e = 4 Then
ActiveDocument.Content.InsertAfter Text:=.FoundFiles(i) & vbCr
End If
Next i
MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件。", vbOKOnly + vbExclamation, "循环遍历文件夹_集成"
Else
MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_集成": End
End If
End With
If e = 4 Then ActiveDocument.Content.Find.Execute findtext:=".doc", replacewith:="", Replace:=wdReplaceAll: ActiveDocument.Content.Characters.Last.Delete
If e = 2 Or e = 4 Then MsgBox "文档尚未保存!请自行保存!", vbOKOnly + vbExclamation, "循环遍历文件夹_集成"
End Sub
Sub SingleDoc()
ActiveDocument.Content.Font.Color = wdColorRed
ActiveDocument.Close savechanges:=wdSaveChanges
End Sub |
评分
-
1
查看全部评分
-
|