当前位置:笔趣阁>网游小说>日常生活工作学习知识积累> 多个Word文档合并为一个文档的方法
阅读设置(推荐配合 快捷键[F11] 进入全屏沉浸式阅读)

设置X

多个Word文档合并为一个文档的方法(2 / 2)

2. 按`Alt + F11`打开VBA编辑器。

3. 插入一个新模块,并输入以下宏代码:

```vba

Sub CombineDocuments  Dim myDoc As Document

Dim filePath As String

Dim fileName As String

Dim folderPath As String

' 设置文件夹路径

folderPath = "C:\YourFolderPath\" ' 更改为你的文件夹路径

' 获取文件夹中第一个Word文件

fileName = Dir(folderPath & "*.docx")

' 循环遍历所有文件

Do While fileName <>

' 打开文件

Set myDoc = Documents.Open(folderPath & fileName)

' 将内容添加到主文档

ActiveDocument.Content.InsertAfter myDoc.Content

' 关闭打开的文档

myDoc.Close False

' 获取下一个文件

fileName = Dir  Loop

End Sub

```

4. 运行宏,将指定文件夹中的所有Word文档合并到当前打开的文档中。

选择适合你的方法进行操作,就可以快速将多个Word文档合并为一个。

上一页 目录 +书签 下一章