使用 VBA 提取 word 文档中的表格数据新建一个 excel 文档,在 VBA 编辑界面操作添加用户界面:代码:Private Sub CommandButton1_Click()Dim s As Strings = TextBox2.TextDim fs, myfolder, myfile, myfiles, wdapp, mydocDim mTable As Table, mCell As CellSet fs = CreateObject(”Scripting.FileSystemObject”)Set myfolder = fs。GetFolder(s)Set myfiles = myfolder.FilesDim m, n As Integerm = 0n = 1For Each myfileInmyfiles m = m + 1 Set wdapp = CreateObject(”word。application")wdapp。Documents.Openmyfile。Path 'wdapp.Visible = Falsewdapp。Visible = True Set mydoc = wdapp.Documents。Item(myfile。Name) For Each mTableInmydoc.Tables For Each mCell In mTable.Range。CellsThisWorkbook.ActiveSheet 。 Cells(m , n ) = Left(mCell 。 Range 。 Text , Len(mCell.Range。Text) - 1) n = n + 1 Next mCell Next mTable Set mydoc = Nothingwdapp。Quit TextBox1.Text = TextBox1.Text + vbCrLf + "已完成第" + Str(m) + "项:” +myfile。Path n = 1NextTextBox1.SetFocusTextBox1。Text = TextBox1。Text + vbCrLf + ”全部完成!共计” + Str(m) + "项”MsgBox ("全部完成!共计” + Str(m) + ”项”)End Sub