|
程序在word中
Sub test()
Dim ph As Paragraph
Dim gsName, je As String
Dim r, c As Integer
Dim path As String
Dim tb As Word.Table
Dim wdFile As String
Dim doc As Document
path = ThisDocument.path
wdFile = Dir(path & "\*.docx")
Dim arr(200, 2)
Dim i As Integer
i = 0
Do While wdFile <> ""
Set doc = Application.Documents.Open(path & "\" & wdFile)
For Each ph In doc.Paragraphs
gsName = ph.Range.Text '取出公司名称
If Len(gsName) > 1 Then Exit For
Next
gsName = getText(gsName)
Set tb = doc.Tables(1)
r = tb.Rows.Count: c = tb.Columns.Count
je = getText(tb.Cell(r, c - 1).Range.Text) '取出合计
arr(i, 0) = gsName: arr(i, 1) = je
i = i + 1
doc.Close
wdFile = Dir
Loop
Dim excel As Object
Set excel = CreateObject("excel.application")
Dim book As Object
Set book = excel.workbooks.Open(path & "\结果.xlsx")
book.worksheets(1).Range("a2").Resize(200, 2).Value = arr
excel.Visible = True
End Sub
Function getText(ByVal txt As String) As String
getText = Mid(txt, 1, Len(txt) - 1)
End Function |
|