|
- Dim mf&
- Sub lqxs()
- Dim Fso As Object, sPath$, WD As Object, i&, Arrf$(), aa, nm$, wj$, intWords%
- Dim doc As Object
- sPath = ThisWorkbook.Path & ""
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set WD = CreateObject("Word.Application")
- WD.Visible = False
- Sheet1.Activate
- [a2:b500].ClearContents
- Call GetFiles(sPath, Fso, Arrf)
- For i = 1 To UBound(Arrf)
- aa = Split(Arrf(i), "")
- nm = aa(UBound(aa))
- wj = Split(nm, ".")(0)
- Cells(i + 1, 1) = wj
- Set doc = WD.documents.Open(Arrf(i))
- intWords = WD.ActiveDocument.BuiltinDocumentProperties(15)
- Cells(i + 1, 2) = intWords
- doc.Close
- Set doc = Nothing
- Next
- Set WD = Nothing
- End Sub
- Sub GetFiles(ByVal sPath$, ByRef Fso As Object, ByRef Arrf$())
- Dim Folder As Object
- Dim SubFolder As Object
- Dim File As Object
- Set Folder = Fso.GetFolder(sPath)
-
- For Each File In Folder.Files
- If InStr(File, ".doc") Then
- mf = mf + 1
- ReDim Preserve Arrf(1 To mf)
- Arrf(mf) = File.Path
- End If
- Next
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder.Path, Fso, Arrf)
- Next
- If mf = 0 Then MsgBox "没有文件,程序退出。"
- Set Folder = Nothing
- Set File = Nothing
- End Sub
复制代码 |
评分
-
查看全部评分
|