|
Sub lx()
Dim wdapp As Object, wd As Object, i%, w$
Sheet1.Range("a2:c3").ClearContents
w = Dir(ThisWorkbook.Path & "\*.doc")
's = Replace(w, ".doc", "")'这一句写错地方了
Set wdapp = CreateObject("word.application")
wdapp.Visible = True
Do
s = Replace(w, ".doc", "")'移到这里应该就可以了,你再试试
m = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1
Set wd = wdapp.documents.Open(ThisWorkbook.Path & "\" & w)
a = wd.tables.Count
With wd.tables(a)
b = .Range.Cells.Count
For i = b To 1 Step -1
If InStr(.Range.Cells(i).Range.Text, "-") > 0 Then
Sheet1.Cells(m, 1).Value = s
Sheet1.Cells(m, 2).Value = Left(.Range.Cells(i - 3).Range.Text, Len(.Range.Cells(i - 3).Range.Text) - 2)
Sheet1.Cells(m, 3).Value = Left(.Range.Cells(i).Range.Text, Len(.Range.Cells(i).Range.Text) - 2)
Exit For
End If
Next i
End With
wd.Close 0
w = Dir
Loop Until w = ""
End Sub |
|