|
楼主 |
发表于 2021-11-9 10:44
|
显示全部楼层
本帖最后由 Jupiterss 于 2021-11-9 15:54 编辑
经过几天的调整,最后结果如下:- Sub ReadFromWord()
- Dim oWordApp As Object, oDoc As Object, txt$
- Dim myPath$, MyName$, k%, Result(1 To 2000, 1 To 12)
-
- 'On Error Resume Next
- With Sheet1
- .UsedRange.Offset(1).ClearContents
- myPath = ThisWorkbook.Path & ""
- MyName = Dir(myPath & "*.doc*")
- Set oWordApp = CreateObject("Word.Application")
-
- Do While MyName <> ""
- If InStr(MyName, "项目") > 0 Then
- Set oDoc = GetObject(myPath & MyName)
- txt = oDoc.Range.Text
- txt = txt & vbLf & Chr(13)
- txt = Replace(txt, ":", ":")
- oDoc.Close False
-
- k = k + 1
- Result(k, 1) = k
- Result(k, 2) = RegxFind(txt, "(.+?)\s", 0) '机构名称
- Result(k, 3) = RegxFind(txt, "成立时间:(.*?)\s", 0) '成立时间
- Result(k, 4) = RegxFind(txt, "资本类型:(.*?)\s", 0) '资本类型
- Result(k, 5) = RegxFind(txt, "[资本性质|机构性质]:(.*?)\s", 0) '资本性质
- Result(k, 6) = RegxFind(txt, "投资阶段:(.*?)\s", 0) '投资阶段
- Result(k, 7) = RegxFind(txt, "(.*)资本类型:?", 0) '关注赛道
- Result(k, 8) = RegxFind(txt, "[机构总部|注册地点]:(.*?)\s", 0) '总部
- Result(k, 9) = RegxFind(txt, "联系电话:(.*?)\s", 0) '联系电话
- Result(k, 10) = RegxFind(txt, "BP投递.*?:(.*?)\s", 0) 'BP邮箱地址
- Result(k, 11) = RegxFind(txt, "官方网站:(.*?)\s", 0) '官网
- Result(k, 12) = RegxFind(txt, "地址:(.*?)\s", 0) '地址
- End If
- MyName = Dir
- Loop
- If k > 0 Then
- .Range("A2").Resize(k, 12) = Result
- End If
- Set oWordApp = Nothing
- End With
- MsgBox "完成"
- End Sub
- Function RegxFind(strValue As String, strFind As String, Num As Integer) As String
- Dim RegX As Object, objMatchs As Object
- Dim strTemp As String
-
- Set RegX = CreateObject("vbscript.regexp")
- RegX.Pattern = strFind
-
- Set objMatchs = RegX.Execute(strValue)
- If objMatchs.Count > 0 Then
- strTemp = objMatchs(0).SubMatches(Num)
- End If
-
- Set RegX = Nothing
- RegxFind = strTemp
- End Function
复制代码 分享出来,给以后有类似需求的人一点点帮助。
最后,非常感谢期间给以指导的各位老师!
|
|