|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 182197315 于 2017-9-20 22:55 编辑
Sub 从word中提取信息到excel()
Dim mypath$, myfile$, str$, k%, arr(1 To 1000, 1 To 6)
Dim wordApp As Object
Dim wordD As Word.Document
mypath = ThisWorkbook.Path & "\"
myfile = Dir(mypath & "*.doc?")
Set wordApp = CreateObject("word.Application")
Do While myfile <> ""
k = k + 1
arr(k, 1) = Left(myfile, InStr(myfile, "."))
arr(k, 3) = Left(arr(k, 1), InStr(arr(k, 1), ":") - 1)
arr(k, 4) = Right(arr(k, 1), Len(arr(k, 1)) - InStr(arr(k, 1), ":") - 1)
Set wordD = wordApp.Documents.Open(mypath & myfile)
str = wordD.Range.Text
arr(k, 2) = RegFind(str, "(\S+)(?=印发)")
arr(k, 5) = RegFind(str, "似稿:([\u4e00-\u9fa5]{1,4})|供稿:([\u4e00-\u9fa5]{1,4})")
arr(k, 6) = RegFind(str, "签发人:([\u4e00-\u9fa5]{1,4})")
wordD.Close
myfile = Dir
Loop
Range("a6").Resize(k, 6) = arr
Set wordD = Nothing
wordApp.Quit
End Sub
Function RegFind(strValue As String, strFind As String) As String
Dim reg As Object, Mat As Object
Set reg = CreateObject("vbscript.regexp")
reg.Pattern = strFind
Set Mat = reg.Execute(strValue)(0)
Set Reg= Nothing
RegFind = Mat
End Function
|
评分
-
1
查看全部评分
-
|