|
大神求助!
想要提取word文档中表格里的数据,提取的结果却是整个word文档的内容。word文件见附件。代码如下:
请帮忙看下是什么问题
- Sub test()
- Dim doc As Object
- Dim path As String, file As String
- Dim s As Integer
- Dim arr(1 To 3000, 1 To 13) As String
-
- Application.ScreenUpdating = False
-
- Range("a2:i30000").ClearContents
-
- path = ThisWorkbook.path & ""
- file = Dir(path & "*.doc")
-
- Sheet2.Cells(1, 2) = file
- Sheet2.Cells(1, 3) = (Len(f) > 0)
-
- Do While Len(file) > 0
- Set doc = GetObject(path & file)
- Sheet2.Cells(1, 3) = path
- With doc.Tables(1)
-
- Sheet2.Cells(1, 4) = "11111"
- arr(1, 1) = zh(.cell(1, 1).Range.Text)
- doc.Close False
- End With
- file = Dir()
- Loop
- Range("C2").Resize(1, 1) = arr
- End Sub
- Function zh(str As String) As String '去除字符
- zh = Replace(str, Chr$(13) & Chr$(7), "")
- End Function
复制代码
|
|