|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 loquat 于 2015-3-9 21:53 编辑
楼主你的表格太不规范了。请测试看看- Sub 提取内容_MeThee() '只生成Excel,不自动保存。
- Application.ScreenUpdating = False
- Dim aCount&, aTable As Table
- Dim arr, brr, i&
- With ThisDocument
- aCount = .Tables.Count
- ReDim arr(1 To aCount, 1 To 5)
- For i = 1 To aCount
- Set aTable = .Tables(i)
- brr = Split(aTable.Range.Text, Chr(7))
- If UBound(brr) = 108 Then
- j = j + 1
- arr(2 * j - 1, 1) = Left(brr(13), Len(brr(13)) - 1)
- arr(2 * j - 1, 2) = Left(brr(39), Len(brr(39)) - 1)
- arr(2 * j - 1, 3) = Left(brr(8), Len(brr(8)) - 1)
- arr(2 * j - 1, 4) = Left(brr(44), Len(brr(44)) - 1)
- arr(2 * j - 1, 5) = Left(brr(49), Len(brr(49)) - 1)
- arr(2 * j, 1) = Left(brr(66), Len(brr(66)) - 1)
- arr(2 * j, 2) = Left(brr(92), Len(brr(92)) - 1)
- arr(2 * j, 3) = Left(brr(61), Len(brr(61)) - 1)
- arr(2 * j, 4) = Left(brr(97), Len(brr(97)) - 1)
- arr(2 * j, 5) = Left(brr(102), Len(brr(102)) - 1)
- End If
- Next
- End With
- Set aExcel = CreateObject("Excel.Application")
- aExcel.Visible = True
- Set aBook = aExcel.workbooks.Add
- Set aSheet = aBook.worksheets("Sheet1")
- aSheet.Range("A1").Resize(1, 5) = [{"姓名","身份证","电话","户籍地","居住地"}]
- aSheet.Range("A2").Resize(aCount, 5) = arr
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|