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

相关推荐
weixin_416660078 小时前
多个 Markdown 文件批量转 Word:PowerShell + Pandoc,连同图片和公式一起检查
word·豆包·deepseek
必须得开心呀9 小时前
为什么 python-docx 打不开加密的 .docx,Word COM 却能打开
python·word
扶风ff9 小时前
练题簿在线免费刷题:会员线下组卷、Word 试卷与成绩导入,课堂检测更方便
java·开发语言·算法·小程序·word
百数平台10 小时前
百数表格知识库配置指南:Excel/CSV 上传、表结构字段类型与 NL2SQL 查询全说明
excel
葡萄城技术团队11 小时前
在 DSH 中直接查看和编辑 Excel:dsh-spreadjs-editor 开源插件发布
excel
开开心心就好12 小时前
视频里的图片怎么提取?双击一下就导出
java·前端·人工智能·spring·智能手机·intellij-idea·excel
葡萄城技术团队14 小时前
从 AI 生成到在线预览:dsh-spreadjs-editor 补齐 DSH 的 Excel 任务闭环
excel
泡海椒14 小时前
JQuick-Excel 实战:用 STYLE 配置单元格与区域样式
开发语言·python·excel
优选资讯1 天前
标签打印软件怎么对接 Excel 数据
前端·excel
泡海椒1 天前
JQuick-Excel 实战:FORMAT 管理日期与数字的 Excel 显示
开发语言·python·excel