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

相关推荐
simple_whu10 小时前
目录中不显示标题中间的软换行符Shift+Enter
word·office
梦幻通灵10 小时前
Excel工作表的复制实战【实用指南】
excel
weixin_4166600710 小时前
2026年 DeepSeek 导出 Word 完全指南
word
ManageEngineITSM12 小时前
功能越来越强,但 IT 使用体验却越来越差
大数据·excel·资产管理·itsm·工单系统
傻啦嘿哟12 小时前
如何使用 Python 操作 Excel 图片:插入、提取与压缩
开发语言·python·excel
石马马户13 小时前
Excel 根据A列标签拆分为多个列数据
excel
珞瑜·14 小时前
【word】撰写文章中实用快捷键
word
骆驼爱记录14 小时前
Word目录:标题加粗页码不加粗技巧
自动化·word·excel·wps·新人首发
城数派14 小时前
1985-2024年各省市县不同土地覆盖类型的土地面积(Excel)
数据库·arcgis·信息可视化·数据分析·excel
开开心心_Every15 小时前
轻松加密文件生成exe,无需原程序解密
运维·服务器·网络·电脑·excel·consul·memcache