|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 huarong7984 于 2024-4-10 12:34 编辑
所发示例,系在2楼代码基础上,稍作修改:去除了数字单元格前的撇号,保留了文本单元格格式输出,美化了表格,仅供参考
Sub TEST()
Dim str As String, reg As Object, ar()
Dim wdcx As Object, wd As Object, rg As Range
Range("A:P").Clear '清除数据及格式
Set wdcx = CreateObject("word.application")
Set reg = CreateObject("Vbscript.Regexp")
ar = Array("位于(\S+)住宅房地产", "天外", "面积(\d+\.?\d+)平方米", "单价为:(\S+) 元", "价值为:(\S+) 元", _
"币:([一-龢]+整)", "于(\d+)年", "总层数为(\d+)层", "所在层数为(\d+)层", "估价对象(\S+)估价目的", _
"价值时点:(\S+)。", "天外", "天外", "]第(\S+)号", "向([一-龢]+)股份")
str = Dir("" & ThisWorkbook.Path & "\*.doc*")
k = 0
mm = Sheet2.Cells(Rows.Count, 2).End(xlUp).Row + 1
Application.ScreenUpdating = False
Do While str <> ""
Text = ""
Set wd = wdcx.documents.Open(ThisWorkbook.Path & "\" & str)
wdcx.Visible = True
x = wd.Paragraphs.Count '总段落数
For Each para In wd.Paragraphs
Text = Text & para.Range.Text
Next para
Set rg = Sheet2.Range("a" & mm)
For i = 0 To UBound(ar)
k = k + 1
With reg
.Global = True
.Pattern = ar(i)
If .TEST(Text) Then
Set m = .Execute(Text)
s = m.Item(0).submatches(0)
rg.Offset(0, k) = "" & s '去除了引号中的 ' 撇号,即对应单元格前不带 ' 撇号
Range("O:O").NumberFormat = "@" '设置单元格O列的数据类型为文本
Else
rg.Offset(0, k) = "不用管"
End If
End With
Next
mm = mm + 1
k = 0
str = Dir
Range("B1:P1") = Array("位置", "小区名称", "建筑面积", "单价:元/平米", "抵押价值:元", "人民币大写", _
"建成日期", "总层数", "所在层数", "估价对象位置", "价值时点", "报告日期", "到期日期", "告知函编号", "申请贷款银行") '填充列标题
Range("B1:P1").Interior.Color = RGB(254, 248, 236) '单元格B1:P1的背景颜色为浅黄色
Range("A:P").EntireColumn.AutoFit '自动调整单元格列宽
Range("A:P").EntireRow.AutoFit '自动调整单元格行高
Range("A1:P1").HorizontalAlignment = xlCenter '设置单元格A1:P1的水平对齐方式为居中
Range("A1:P1").Font.Bold = True 'A1:P1字体为加粗
[A1].CurrentRegion.Borders.LineStyle = xlContinuous '添加边框
wd.Save
wd.Close
Loop
wdcx.Quit
Set wdcx = Nothing
Set wd = Nothing
Application.ScreenUpdating = True
End Sub
|
|