如果你的word文件没有表格,那么使用doc.tables(1)获取就会报错。
你可以判断表格个数 if doc.tables.count >= 1 then
For Each AAA As String In filesys .GetFiles("d:\lzxx1")
Dim app As New MSWord.Application
try
Dim fileName = AAA
Dim doc = app.Documents.Open(fileName)
Dim t = doc.Tables(1)
Dim text = t.Cell(1, 2).Range.Text.ToString()
text = text.Substring(0, text.Length - 2)
Dim nr As Row = Tables("表A").AddNew
'Dim t = doc.Tables(1)
' Dim text = t.Cell(1, 2).Range.Text.ToString()
' text = text.Substring(0, text.Length - 2)
nr("姓名") = text
app.ActiveWindow.Selection.WholeStory
For Each shape As object In app.ActiveWindow.Selection.InlineShapes
If shape.Type = MSWord.WdInlineShapeType.wdInlineShapePicture
Dim img As Byte() = shape.Range.EnhMetaFileBits
Dim bmp As new Bitmap(new IO.MemoryStream(img))
bmp.Save(ProjectPath & "Attachments/" & nr("姓名") & ".jpg")
End If
Next
nr("照片") = nr("姓名") & ".jpg"
Doc.Close
catch ex As exception
'msgbox(ex.message)
finally
app.Quit
End try
Next