|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下- Sub t()
- Dim word, doc, obj, pro, fs, mpath, k, s, txt, fso, f, r%
- mpath = ThisWorkbook.Path & "" & "示例"
- Set pro = CreateObject("winmgmts:\\.\root\cimv2")
- Set obj = pro.execquery("select * from win32_process")
- Set fso = CreateObject("scripting.FileSystemObject")
- Set fs = fso.getfolder(mpath).Files
-
- '如果有winword.exe进程,则kill掉
- For Each k In obj
- If k.Name = "WINWORD.EXE" Then Shell "cmd.exe /c taskkill /f /t /pid " & k.processID
- Next k
-
- r = 3
- For Each f In fs
- If Not f.Name Like "~*" Then
- If Split(f, ".")(1) = "doc" Then
- Set word = CreateObject("Word.Application")
- Set doc = word.Documents.Open(mpath & "" & f.Name)
- fs = doc.sections(1).headers(1).Range
- s = Split(fs, " ")
- txt = Split(doc.Content.Text, " ")
- With Sheet2
- .Cells(r, "a") = r - 2
- .Cells(r, "b") = txt(LBound(txt))
- .Cells(r, "c") = s(UBound(s))
- r = r + 1
- End With
- doc.Close
- word.Quit
- End If
- End If
- Next f
- Set doc = Nothing
- Set word = Nothing
- Set obj = Nothing
- Set pro = Nothing
- Set fso = Nothing
- End Sub
复制代码 |
|