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中。

相关推荐
鲲穹AI种草12 小时前
Excel 表格批量处理与数据整理,多款表格工具能力客观记录
excel·表格处理
cspttty14 小时前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel
鲲穹AI种草15 小时前
Word 文稿批量规范化处理,多款 Word 批量处理工具能力客观记录
word·批量处理·页面页脚
SunnyDays10111 天前
使用 Python 提取 Word 文档中的表格数据
python·word
weixin_416660071 天前
DeepSeek生成的数学公式怎么导出到Word并保持可编辑?
word·deepseek
Zzq_Fighting2 天前
Excel批量匹配数据
excel
蝶恋舞者2 天前
Word 实现「图 X」序号自动递增 和交叉引用
word
E_ICEBLUE2 天前
Python 实现 Excel 转 Markdown,支持工作表、单元格区域和批量处理
python·excel·markdown·格式转换
拆房老料2 天前
ONLYOFFICE 集群部署实战:9.3 多实例方案与 9.4 架构变化
开源·word·excel·开源软件·ppt
ms365copilot2 天前
Excel Copilot挖掘数据洞察,不用精通函数也能做数据分析 (1)
数据分析·excel·copilot