|
楼主,请备份后应用下面的宏:
- Sub LoopDir循环遍历文件夹_表格批量转文本()
- On Error Resume Next
- Dim objShell As Object
- Dim objFolder As Object
- Dim SearchPath As String
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.BrowseForFolder(0, "请选择文件夹!", 0, 0)
- SearchPath = objFolder.self.Path & ""
- If MsgBox("请确认!是否处理文件夹 " & SearchPath & " ?", 4 + 16) = vbNo Then Exit Sub
- Set objShell = Nothing
- Set objFolder = Nothing
- Dim DicList As Object
- Dim FileList As Object
- Dim Key
- Dim NowDic As String
- Dim NowFile As String
- Dim i As Long
- Dim FileName, FilePath
- Set DicList = CreateObject("Scripting.Dictionary")
- Set FileList = CreateObject("Scripting.Dictionary")
- DicList.Add SearchPath, ""
- i = 0
- Do While i < DicList.Count
- Key = DicList.keys
- NowDic = Dir(Key(i), vbDirectory)
- Do While NowDic <> ""
- If (NowDic <> ".") And (NowDic <> "..") Then
- If (GetAttr(Key(i) & NowDic) And vbDirectory) = vbDirectory Then DicList.Add Key(i) & NowDic & "", ""
- End If
- NowDic = Dir()
- Loop
- i = i + 1
- Loop
- For Each Key In DicList.keys
- NowFile = Dir(Key)
- Do While NowFile <> ""
- FileList.Add NowFile, Key
- NowFile = Dir()
- Loop
- Next
- Dim doc As Document
- Dim x&
- Dim t As Table
- i = 0
- FileName = FileList.keys
- FilePath = FileList.Items
- Do While i < FileList.Count
- If FilePath(i) & FileName(i) Like "*.doc*" Then
- Set doc = Documents.Open(FileName:=FilePath(i) & FileName(i), Visible:=False)
- For Each t In doc.Tables
- With t.Range.Rows
- .WrapAroundText = False
- .ConvertToText Separator:=wdSeparateByTabs, NestedTables:=True
- End With
- Next
- doc.Close SaveChanges:=wdSaveChanges
- x = x + 1
- End If
- i = i + 1
- Loop
- Set DicList = Nothing
- Set FileList = Nothing
- MsgBox "文件夹包含 " & i & " 个文件!" & vbCr & "共处理 Word 文档(*.docx/*.doc) " & x & " 个!", 0 + 48
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|