|
- Sub Doc2Excel()
- Dim i%, j%, k%, iCellCount%, arr(), brr(), tbl, cell As cell, exApp As Object, sht, file
- On Error Resume Next
- With Application.FileDialog(msoFileDialogFilePicker)
- .Filters.Clear
- .Filters.Add "所有WORD文件", "*.doc,*.docx", 1
- .AllowMultiSelect = True
- If .Show <> -1 Then Exit Sub
- For Each file In .SelectedItems
- With GetObject(file)
- If .Tables.Count = 1 Then
- j = 0
- k = k + 1
- Set tbl = .Tables(1)
- iCellCount = tbl.Range.Cells.Count
- ReDim Preserve arr(1 To 500, 1 To iCellCount / 2)
- ReDim Preserve brr(1 To iCellCount / 2)
- If k = 1 Then
- For i = 1 To iCellCount
- If i Mod 2 Then brr((i + 1) / 2) = Replace(tbl.Range.Cells(i).Range.Text, Chr(13) & Chr(7), "")
- Next i
- End If
- For i = 1 To iCellCount
- If i Mod 2 = 0 Then
- j = j + 1
- arr(k, j) = Replace(tbl.Range.Cells(i).Range.Text, Chr(13) & Chr(7), "")
- End If
- Next i
- End If
- .Close False
- End With
- Next
- End With
- Set exApp = GetObject(, "excel.application")
- If Err <> 0 Then
- Err.Clear
- Set exApp = CreateObject("excel.application")
- End If
- Set sht = exApp.Workbooks.Open(ThisDocument.Path & "" & "New Microsoft Excel Worksheet.xlsx").sheets(1)
- sht.Cells.Clear
- sht.[a1].Resize(1, UBound(brr)) = brr
- ReDim Preserve arr(1 To k, 1 To iCellCount / 2)
- sht.[a2].Resize(k, UBound(brr)) = arr
- sht.Parent.Close True
- 'sht.Parent.Windows(1).Visible = True
- exApp.Quit
- Set exApp = Nothing
- MsgBox "OK!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|