使用VBA提取word文档中的表格数据新建一个excel文档,在VBA编辑界面操作添加用户界面:
UserForml
[■ ' ...... p ... ' ■ ' ■ ■ ' 日B
「文件挪径:
■■ I !l ■ r l ■ I ?I M I 1 ■< 'I
开始
代码:
Private Sub Comma ndButto n1_Click()
Dim s As Stri ng
s = TextBox2.Text
Dim fs, myfolder, myfile, myfiles, wdapp, mydoc
Dim mTable As Table, mCell As Cell
Set fs = CreateObject("Scriptin g.FileSystemObject")
Set myfolder = fs.GetFolder(s)
Set myfiles = myfolder.Files
Dim m, n As In teger
m = 0
n = 1
For Each myfile In myfiles
m = m + 1
Set wdapp = CreateObject("word.applicati on")
wdapp.Docume nts.Ope n myfile .P ath
'wdapp.Visible = False
wdapp.Visible = True
Set mydoc = wdapp.Docume nts.l tem(https://www.wendangku.net/doc/c216274760.html,)
For Each mTable In mydoc.Tables
For Each mCell In mTable.Ra nge.Cells
ThisWorkbook.ActiveSheet.Cells(m, n) = Left(mCell.Ra nge.Text, Le n(mCell.Ra nge.Text)- n =
n + 1
Next mCell
Next mTable
Set mydoc = Noth ing wdapp.Quit
TextBoxl.Text = TextBoxl.Text + vbCrLf + 巴完成第” + Str(m) + "项:” + myfile.Path n = 1 Next
TextBox1.SetFocus
TextBox1.Text = TextBox1.Text + vbCrLf + 全部完成!共计” + Str(m) + "项”
MsgBox (”全部完成!共计” + Str(m) + "项”)
End Sub