续貂:引用守柔老师的宏,并同时按楼主意思汇总至一个表中(代码改动部分已突出显示) Option Explicit Sub GetDocTablletoSheet() '请在EXCEL VBE中引用MS WORD Dim wdApp As Word.Application, wdDoc As Word.Document, wdTable As Word.Table Dim strArray() As Variant, xlSheet As Worksheet, myDialog As FileDialog, oSel As Variant Dim myArray(7) As String, r As Integer On Error Resume Next '定义一个一维数组 strArray = Array("车型代号", "整车编号", "内部尺寸", "发动机型号", "轴距(mm)", "车身", "变速箱(型式/型号)", "型式/型号") Set wdApp = New Word.Application '取得一个New Word对象 Set myDialog = Application.FileDialog(msoFileDialogFilePicker) With myDialog .Filters.Clear '清除所有文件筛选器中的项目 .Filters.Add "所有 WORD 文件", "*.doc", 1 '增加筛选器的项目为所有WORD文件 .AllowMultiSelect = True '允许多项选择 If .Show = -1 Then '确定 Application.ScreenUpdating = False For Each oSel In .SelectedItems '在所有选取项目中循环 Set wdDoc = wdApp.Documents.Open(Filename:=oSel, Visible:=False) Set wdTable = wdDoc.Tables(1) With wdTable '将指定的单元格内容赋值给数组 myArray(0) = Replace(.Cell(3, 2).Range.Text, Chr(13) & Chr(7), "") myArray(1) = Replace(.Cell(5, 2).Range.Text, Chr(13) & Chr(7), "") myArray(2) = Replace(.Cell(13, 4).Range.Text, Chr(13) & Chr(7), "") myArray(3) = Replace(.Cell(15, 5).Range.Text, Chr(13) & Chr(7), "") myArray(4) = Replace(.Cell(16, 3).Range.Text, Chr(13) & Chr(7), "") myArray(5) = Replace(.Cell(22, 3).Range.Text, Chr(13) & Chr(7), "") myArray(6) = Replace(.Cell(26, 3).Range.Text, Chr(13) & Chr(7), "") myArray(7) = Replace(.Cell(29, 4).Range.Text, Chr(13) & Chr(7), "") End With wdDoc.Close False
r = r + 1'以下开始稍作更改 Sheets(1).Range(Cells(r, 1), Cells(r, 8)).Value = myArray '为单元格区域赋值 Next With Sheets(1) .Rows(1).Insert .[A1:H1].Value = strArray .UsedRange.Columns.AutoFit End With End If End With wdApp.Quit Set wdApp = Nothing Application.ScreenUpdating = True '恢复屏幕更新 End Sub
[此贴子已经被作者于2007-12-4 10:22:30编辑过] |