将多个 MS Word 文档转换为 txt 文件(少量额外位)
Converting multiple MS Word documents into txt files (few extra bits)
我目前正致力于将大量 MS Word 表单传输到数据库系统中。
我目前的做法是:
- 打开单字文档
- 转到高级选项更改保存设置,以便仅将表单数据保存为带分隔符的文本文件
- 保存点击确定弹出提示windows
- 使用cmd合并所有txt文件
- 导入 excel 并在那里处理
希望在这些阶段结束时,我将获得一个经过相当整理的 excel 信息文件,可以将其传输到数据库系统。
我的问题是,由于我有很多word文档(我看了大约100个之后感觉像个机器人),我可以将1)2)和3)的过程自动化吗?
任何帮助将不胜感激,我之前在 python 中编写过脚本并完成了一些简单的编程,但欢迎任何解决方案。
您可以使用 VBA 宏自动执行步骤 1-3。使用 Document.SaveAs
方法,您可以将表单数据仅保存到 txt 文件:
ActiveDocument.SaveAs ActiveDocument.FullName & ".txt", _
WdSaveFormat.wdFormatText, SaveFormsData:=True
然后您可以调用此 SaveAs
方法循环遍历给定文件夹中的所有文档:
Sub SaveAllFormData(path As String)
Dim doc As Document
Dim fileName As String
fileName = Dir(path & "*.doc")
' Loop through all .doc files in that path
Do While fileName <> ""
Set doc = Application.Documents.Open(path & fileName)
' Save form data
doc.SaveAs2 doc.FullName & ".txt", WdSaveFormat.wdFormatText, SaveFormsData:=True
doc.Close wdDoNotSaveChanges
fileName = Dir
Loop
End Sub
如果您在设置和 运行 宏方面需要帮助,请查看文档:Create or run a macro
我建议您使用以下免费且更简单的解决方案:
multidoc-converter.com/en/download/index.html
对我有用。
我目前正致力于将大量 MS Word 表单传输到数据库系统中。
我目前的做法是:
- 打开单字文档
- 转到高级选项更改保存设置,以便仅将表单数据保存为带分隔符的文本文件
- 保存点击确定弹出提示windows
- 使用cmd合并所有txt文件
- 导入 excel 并在那里处理
希望在这些阶段结束时,我将获得一个经过相当整理的 excel 信息文件,可以将其传输到数据库系统。
我的问题是,由于我有很多word文档(我看了大约100个之后感觉像个机器人),我可以将1)2)和3)的过程自动化吗?
任何帮助将不胜感激,我之前在 python 中编写过脚本并完成了一些简单的编程,但欢迎任何解决方案。
您可以使用 VBA 宏自动执行步骤 1-3。使用 Document.SaveAs
方法,您可以将表单数据仅保存到 txt 文件:
ActiveDocument.SaveAs ActiveDocument.FullName & ".txt", _
WdSaveFormat.wdFormatText, SaveFormsData:=True
然后您可以调用此 SaveAs
方法循环遍历给定文件夹中的所有文档:
Sub SaveAllFormData(path As String)
Dim doc As Document
Dim fileName As String
fileName = Dir(path & "*.doc")
' Loop through all .doc files in that path
Do While fileName <> ""
Set doc = Application.Documents.Open(path & fileName)
' Save form data
doc.SaveAs2 doc.FullName & ".txt", WdSaveFormat.wdFormatText, SaveFormsData:=True
doc.Close wdDoNotSaveChanges
fileName = Dir
Loop
End Sub
如果您在设置和 运行 宏方面需要帮助,请查看文档:Create or run a macro
我建议您使用以下免费且更简单的解决方案: multidoc-converter.com/en/download/index.html
对我有用。