|
- Sub test()
- Dim r%, i%, m%
- Dim arr, brr()
- Dim mypath$, myname$
- Dim myapp As Object
- Dim mydoc As Object
- mypath = ThisWorkbook.Path & ""
- myname = "学生学籍卡.doc"
- If Dir(mypath & myname) = "" Then
- MsgBox mypath & myname & "不存在!"
- Exit Sub
- End If
- Set myapp = CreateObject("word.application")
- Set mydoc = CreateObject("word.document")
- myapp.Visible = True
- Set mydoc = myapp.Documents.Open(Filename:=mypath & myname)
- With mydoc
- ReDim brr(1 To .tables.Count, 1 To 10)
- For k = 1 To .tables.Count
- With .tables(k)
- brr(k, 1) = Replace(.cell(2, 2).Range.Text, Chr(13) & Chr(7), Empty)
- brr(k, 2) = Replace(.cell(2, 4).Range.Text, Chr(13) & Chr(7), Empty)
- brr(k, 3) = Replace(.cell(2, 6).Range.Text, Chr(13) & Chr(7), Empty)
- brr(k, 4) = Replace(.cell(3, 2).Range.Text, Chr(13) & Chr(7), Empty)
- brr(k, 5) = Replace(.cell(3, 6).Range.Text, Chr(13) & Chr(7), Empty)
- brr(k, 6) = Replace(.cell(5, 2).Range.Text, Chr(13) & Chr(7), Empty)
- With .cell(10, 2).tables(1)
- For i = 2 To .Rows.Count
- x = 0
- Select Case Left(.cell(i, 1).Range.Text, 2)
- Case "父亲"
- x = 7
- Case "母亲"
- x = 9
- End Select
- If x <> 0 Then
- brr(k, x) = Replace(.cell(i, 2).Range.Text, Chr(13) & Chr(7), Empty)
- brr(k, x + 1) = Replace(.cell(i, 3).Range.Text, Chr(13) & Chr(7), Empty)
- End If
- Next
- End With
- End With
- Next
- End With
- mydoc.Close False
- myapp.Quit
- With Worksheets("sheet1")
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
-
- End Sub
复制代码 |
|