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_416660071 小时前
从标记语言到 Word 文档:AI 生成的 Mermaid 与 LaTeX 自动化转换的技术方案解析
word·latex·数学公式·deepseek
辉博士1 小时前
Spring Boot+EasyExcel实现Excel文件
java·spring boot·excel
Teable任意门互动2 小时前
多维表格本地化部署实践解析 企业如何实现数据自主可控路径
数据库·excel·钉钉·飞书·开源软件
Eiceblue2 小时前
Python 如何实现 Excel 数据分列?一列拆分为多列
python·microsoft·excel
许杰小刀2 小时前
使用 Python 将 Excel 数据批量导入到数据库中(SQLite)
数据库·python·excel
2501_9307077815 小时前
使用C#代码在 Excel 中添加或设置批注格式
excel
昵称暂无117 小时前
通过 C# 复制 Word 文档、指定段落、指定节
开发语言·c#·word
梦因you而美18 小时前
Python win32com 复制Excel sheet优化:覆盖替换而非删除重建,彻底解决公式报错
python·excel·win32com·python自动化·批量复制sheet表
asdzx6719 小时前
使用 C# 将 Excel 转换成高质量 JPG
开发语言·c#·excel
城数派20 小时前
2014-2025年全国监测站点的逐月空气质量数据(15个指标\Excel\Shp格式)
arcgis·信息可视化·数据分析·excel