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

相关推荐
小白学大数据11 小时前
超简单:用 Python 让 Excel 飞起来:用 openpyxl 把重复报表整理交给脚本
开发语言·数据库·python·excel
几层山下16 小时前
WPS的word文档转pdf java实现不乱格式生成-已解决
java·pdf·word·wps
2601_9622940517 小时前
Python 操作 Word:如何查找、替换和批量修改文本
python·正则表达式·word·文档处理·查找替换
SunnyDays101118 小时前
如何使用 Python 添加和编辑 Excel VBA 宏(无需安装 Excel)
开发语言·python·excel·vba
GHL28427109019 小时前
codex操作excel学习
学习·ai·word·excel
Eiceblue19 小时前
如何构建一个纯前端 Word 转 Markdown 转换器(React + WebAssembly)
前端·react.js·word
圣光SG2 天前
Word 综合实操项目:标准求职简历制作
word
RisunJan2 天前
项目经理面试知识点梳理
面试·职场和发展·word
拆房老料2 天前
LibreOffice 26.8 发布后,再看 BaseMetas FileView 的 Office 转 PDF 技术路线
pdf·word·开源软件·ppt·格式工厂
统计学小王子2 天前
数学建模国赛倒计时8天——《搭建建模Word框架(字体字号)》
数学建模·word