我试图从多个word文档中提取数据(第二列字表中的信息),并将数据编译为一个excel(2011 mac版本)。 以下是示例: the word table
我写了一段代码,但这段代码不起作用。如何修改此代码以使其正常工作?非常感谢!
Sub extractdata()
Dim r As Integer
Dim c As Integer
r = 1
c = 8
Range(Cells(r + 1, ”A”), Cells(65536, c)).ClearContents
Application.ScreenUpdating = False
Dim filename As String, wdapp As Object, erow As Long, fn As String, arr As Variant
Set wordapp = CreateObject("word.application")
filename = Dir(ThisWorkbook.Path & “ \ " & " * .docx”)
Do While filename <> “”
With wordapp.documents.Open(ThisWorkbook.Path & "\" & filename)
For i = 1 To 8
arr = Left(.Table(1).Cells(i, 2))
Next
Cells(erow, “A”).Resize(UBound(arr, 1), 8) = arr
End With
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
未测试:
Sub extractdata()
Dim c As Long
c = 8
Range(Cells(r + 1, "A"), Cells(65536, c)).ClearContents
Application.ScreenUpdating = False
Dim filename As String, wdapp As Object, erow As Long, _
Dim fn As String, i as Long
Set wordapp = CreateObject("word.application")
filename = Dir(ThisWorkbook.Path & "\*.docx")
Do While filename <> ""
With wordapp.documents.Open(ThisWorkbook.Path & "\" & filename)
For i = 1 To c
Cells(erow, i) = Left(.Tables(1).Cell(i, 2)).Range.Text
Next
.Close False
End With
filename = Dir()
Loop
Application.ScreenUpdating = True
End Sub