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

相关推荐
SunnyDays101116 小时前
Python 将 Excel(XLS/XLSX)转换为 JSON:导出工作簿、工作表、单元格区域与自定义 JSON 结构
python·json·excel·excel 转 json·导出 excel 到 json·xlsx 转 json·xls 转 json
chatexcel18 小时前
ChatExcel AI Word 升级:多模态读资料、按模板生成、智能排版配图,还能批注修订和联动Excel 复核
人工智能·ai·word·excel·ai写作
北极糊的狐18 小时前
Excel快速拆分一列数据为两列(领养例子)该摘要描述了如何将包含姓名和电话的混合数据列拆分为单独的两列
excel
搭贝低代码18 小时前
财务管控系统架构设计:从Excel到数字化管控平台的技术跃迁
低代码·系统架构·excel
Metaphor6922 天前
使用 Python 在 Word 文档中添加或删除文本框
python·word
ms365copilot2 天前
Excel 新模型Claude Opus 5
人工智能·excel
CodexDave2 天前
Python 自动化接单实战(二):Excel 批量清洗如何把规则与异常分开
python·自动化·excel·python自动化·数据处理·excel清洗·异常报告
蓝创工坊Blue Foundry2 天前
发票、凭证和对账单怎么整理成 Excel?先定义字段,再逐项复核
pdf·ocr·excel·文心一言·paddlepaddle
ms365copilot2 天前
Copilot直接读取Excel,一键生成完整数据汇报PPT
powerpoint·excel·copilot
石马马户3 天前
excel中使用宏绘制折线图
excel