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

相关推荐
诗词在线1 天前
诗词在线古诗词传播
人工智能·word·php
reasonsummer1 天前
【办公类-142-04】20260330插班生word转长表EXCLE(4)新表重制
python·word
weixin_416660071 天前
解决方案:DeepSeek/ChatGPT生成的内容,如何无损转为Word文档?
chatgpt·word·论文·数学公式·deepseek
骆驼爱记录1 天前
Word双语目录制作全攻略
自动化·word·新人首发
开开心心就好1 天前
桌面图标乱了怎么办,一键恢复固定位置工具
运维·服务器·windows·pdf·excel·3dsmax·houdini
偷心伊普西隆1 天前
EXCEL 自动化链接更新工具设计方案
自动化·excel
ai_coder_ai1 天前
如何在自动化脚本中使用excel文件?
excel·autojs·自动化脚本·冰狐智能辅助·easyclick
前端程序猿i1 天前
纯JS 导出 Excel 工具
开发语言·javascript·excel
✎ ﹏梦醒͜ღ҉繁华落℘1 天前
excel操作 ---删除空行
excel