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

相关推荐
ms365copilot5 小时前
算数据+做图表,Copilot Excel公式+图表联动
excel·copilot
随手工具-Excel, pdf, SQL13 小时前
多个 PDF 怎么合并成一个?免费在线工具,还能混入图片和 Word
pdf·word·效率工具·在线工具·pdf合并·合并pdf
ms365copilot14 小时前
在Copilot聊天中添加Word、Excel 和 PowerPoint 代理
word·excel·copilot
Smilecoc14 小时前
Excel之Subtotal:功能强大的统计函数
excel
用户03321266636716 小时前
使用 Python 在 Excel 中添加或删除批注
python·excel
2601_9659128317 小时前
PDF转Word技术选型:2026年文档解析引擎性能对比与集成评估
pdf·word
大数据张老师17 小时前
Typora 导出 Word 模版操作手册
开发语言·c#·word·typora
观远数据2 天前
Excel继续用、自研BI、替换BI:产品VP拆解三条路线的隐性成本与能力边界
大数据·人工智能·excel
DS随心转小程序2 天前
实测评测 AI 导出鸭转化效能,全方位优化 DeepSeek 输出 word 文档落地使用效率
人工智能·aigc·word·豆包·deepseek·ai导出鸭
用户298698530143 天前
Excel 转 PDF 免费在线工具,格式完美保留
人工智能·c#·excel