|
楼主 |
发表于 2009-10-15 17:02
|
显示全部楼层
还好,自己解决,还有问题啊........
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(10) As String, r As Integer
On Error Resume Next
'定义一个一维数组
strArray = Array("姓名", "性别", "籍贯", "身份证号", "户口所在地", "培训合格证", "最高学历", "学科专业", "职称", "入社时间")
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(1, 2).Range.Text, Chr(13) & Chr(7), "")
myArray(1) = Replace(.Cell(1, 4).Range.Text, Chr(13) & Chr(7), "")
myArray(2) = Replace(.Cell(3, 4).Range.Text, Chr(13) & Chr(7), "")
myArray(3) = Replace(.Cell(5, 2).Range.Text, Chr(13) & Chr(7), "")
myArray(4) = Replace(.Cell(5, 4).Range.Text, Chr(13) & Chr(7), "")
myArray(5) = Replace(.Cell(7, 2).Range.Text, Chr(13) & Chr(7), "")
myArray(6) = Replace(.Cell(8, 2).Range.Text, Chr(13) & Chr(7), "")
myArray(7) = Replace(.Cell(8, 4).Range.Text, Chr(13) & Chr(7), "")
myArray(8) = Replace(.Cell(24, 2).Range.Text, Chr(13) & Chr(7), "")
myArray(9) = Replace(.Cell(26, 2).Range.Text, Chr(13) & Chr(7), "")
End With
wdDoc.Close False
r = r + 1 '以下开始稍作更改
Sheets(1).Range(Cells(r, 1), Cells(r, 11)).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
抄代码,但问题如下:
我的WORD文件里有二张表格,如何提取第二个表的内容?
以上代码中且粗体表示的就是第二个表格要提取的内容, 但返回是空的.....
期待高人出手中.....
[ 本帖最后由 slayerwwj 于 2009-10-16 10:26 编辑 ] |
|