VBA提取word表格内容到excel

这是一段提取word表格中部分内容的vb代码。

vbscript 复制代码
Sub 提取word表格()
mypath = ThisWorkbook.Path & "\"

myname = Dir(mypath & "*.doc*")

n = 4 ' index of rows


Range("A1:F1") = Array("课程代码", "课程名称", "专业", "备用1", "备用2", "备用3")

While myname <> ""

Set mydoc = GetObject(mypath & myname)

m = 4 ' index of rows of a table in word

With mydoc

With .Tables(1)


maxRows = .Rows.Count

'Debug.Print .Cell(2, 10).Range.text

While maxRows - m >= 2

Cells(n, 1) = .Cell(m, 3).Range.text
Cells(n, 1) = Left(Cells(n, 1), Len(Cells(n, 1)) - 1) '去除末尾小黑点,小黑点貌似代表换行符
Cells(n, 2) = .Cell(m, 4).Range.text
Cells(n, 2) = Left(Cells(n, 2), Len(Cells(n, 2)) - 1)

Cells(n, 3) = myname
m = m + 1
n = n + 1

'Cells(3, 1) = .Cell(3, 16).Range.text
'Cells(4, 1) = maxRows

Wend

End With

.Close False

End With

myname = Dir '再次调用,获取下一个文件名

Wend

MsgBox "COMPLETE"

End Sub

上述代码,可以把下面表格中课程代码和课程名称,提取到excel中。

相关推荐
认真的小羽❅17 小时前
0-1手写通用的 Excel 导入/导出工具类
java·excel
catoop17 小时前
Excel 实战技巧:单元格相对引用 INDIRECT、ROW、COLUMN 函数
excel
Teable任意门互动20 小时前
中小企业进销存实战:Teable多维表格从零搭建高效库存管理系统
开发语言·数据库·excel·飞书·开源软件
零零发聊技术1 天前
Excel 2016版的TextJoin函数为什么不能用?
excel·textjoin
catoop1 天前
Excel 实战技巧:动态单元格引用中使用 LET 函数优化 Excel 公式性能与可读性
excel
lengxuemo1 天前
Excel做正态分布图
学习·excel
Eiceblue1 天前
C# 中如何设置 Word 文档页面?(页面大小、边距、方向自动化控制)
c#·自动化·word·visual studio
白白白飘1 天前
【EXCEL】数据透视表学习
学习·excel
一晌小贪欢1 天前
PyQt5 + Pandas 打造常见的表格(Excel/CSV)读取与处理工具
python·qt·excel·pandas·python办公·excel处理
小鹿软件办公1 天前
如何用 Excel 宏原地批量修改单元格内容?
excel·excel重命名