|
一些能从文档中提取表格和图片的软件和插件很多。但大多不是免费的。以下是我在Word环境用VBA编写的宏,该程序的特点有:从Word中提取所有表格;每个表格之前进行编号;新建文件名易于识别文件来源、表格数。
Sub TableCollect ()
If MsgBox("将本文档中的表格提取到新文档,继续吗?", vbOKCancel + vbInformation, "提取表格") = vbOK Then
If ActiveDocument.Tables.Count >= 1 Then
tbcnt = ActiveDocument.Tables.Count
a = ActiveDocument.Name
Documents.Add DocumentType:=wdNewBlankDocument
b = ActiveDocument.Name
Windows(a).Activate
For tb = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(tb).Select
Selection.Copy
Windows(b).Activate
Selection.TypeText Text:="Table - " & tb & " of " & tbcnt
Selection.TypeParagraph
Selection.Paste
Windows(a).Activate
Next
Windows(b).Activate
a = Mid(a, 1, Len(a) - 4)
ChangeFileOpenDirectory "C:"
ActiveDocument.SaveAs FileName:=tb - 1 & "Table(s)Of_" & a & ".doc"
MsgBox "表格文档保存完毕(c:)。" , vbInformation , "保存"
Else:
MsgBox "该文档中无表格。"
End If
End If
End Sub |
|