|
- Sub 批量转换doc2txt()
- On Error Resume Next
- Dim fd As FileDialog, i&, j$, doc As Document, p$, t&
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
- Set fd = Nothing
- j = MsgBox("<是>:doc2txt <否>:txt2doc <取消>:docx2doc", 3 + 48)
- If MsgBox("是否转换文件夹 " & p & " ?", 4 + 48) = vbNo Then End
- If j = vbYes Then
- t = 1
- ElseIf j = vbNo Then
- t = 2
- Else
- t = 3
- End If
- With Application.FileSearch
- .NewSearch
- .LookIn = p
- .SearchSubFolders = True
- If t = 1 Then
- .FileName = "*.doc"
- ElseIf t = 2 Then
- .FileName = "*.txt"
- Else
- .FileName = "*.docx"
- End If
- If .Execute > 0 Then
- For i = 1 To .FoundFiles.Count
- If t = 1 Then
- Set doc = Documents.Open(FileName:=.FoundFiles(i), Visible:=False)
- doc.SaveAs FileName:=Left(doc.FullName, Len(doc.FullName) - 4) & ".txt", FileFormat:=wdFormatText
- ElseIf t = 2 Then
- Set doc = Documents.Open(FileName:=.FoundFiles(i), ConfirmConversions:=False, Visible:=False)
- doc.SaveAs FileName:=Left(doc.FullName, Len(doc.FullName) - 4), FileFormat:=wdFormatDocument
- Else
- Set doc = Documents.Open(FileName:=.FoundFiles(i), Visible:=False)
- doc.SaveAs FileName:=Left(doc.FullName, Len(doc.FullName) - 5), FileFormat:=wdFormatDocument
- End If
- ActiveDocument.Close
- Next i
- MsgBox "转换完毕!共转换 " & .FoundFiles.Count & " 个文件!", 0 + 64
- Else
- MsgBox "未发现文件!", 0 + 16
- End If
- End With
- End Sub
复制代码 |
|