|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Option Compare Text
Function vFilesListDg(ByVal strPath$, ByRef ar(), Optional ByRef iGroup&, _
Optional ByVal strExtension$ = "*", Optional ByVal strExclude As String = "")
Dim Fso As Object, objFold As Object, vFile, vFold
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objFold = Fso.GetFolder(strPath)
For Each vFile In objFold.Files
If Fso.GetExtensionName(vFile.Name) Like strExtension Then
If vFile.Name <> strExclude And Not vFile.Name Like "~$*" Then
iGroup = iGroup + 1
ReDim Preserve ar(1 To 3, 1 To iGroup)
ar(1, iGroup) = objFold.Path & "\"
ar(2, iGroup) = vFile.Path
ar(3, iGroup) = Left(vFile.Name, InStrRev(vFile.Name, ".") - 1)
End If
End If
Next
For Each vFold In objFold.subfolders
vFilesListDg vFold, ar, iGroup, strExtension, strExclude
Next
End Function
Sub test()
Dim wdApp As Object, strFileName$, strPath$, ar(), i&, wdFormatXMLDocument
Call vFilesListDg(ThisWorkbook.Path, ar(), i, "txt", ThisWorkbook.Name)
If i = False Then Exit Sub
Application.ScreenUpdating = False
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
strPath = ThisWorkbook.Path & "\"
For i = 1 To UBound(ar, 2)
With wdApp.documents.Open(ar(2, i))
.SaveAs ar(1, i) & ar(3, i), wdFormatXMLDocument
.Close
End With
Next i
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
3
查看全部评分
-
|