👉
查看更多Office小技巧
👈点击即可查看
打开开发工具
首先点击选择自定义功能区,勾选开发工具
打开Visual Basic
点击开发工具,Visual Basic选项
插入模块
源码撰写
Sub merge_word()
Dim time_start As Single: time_start = Timer
Dim word_result As Document
Dim word_temp As Document
Dim file_dialog As FileDialog
Dim str As String
Dim file
Dim num As Long
Set word_result = ActiveDocument
Set file_dialog = Application.FileDialog(msoFileDialogFilePicker)
With file_dialog
.AllowMultiSelect = True
.Title = "请选择【一个或多个】需要与当前文档合并的文件"
With .Filters
.Clear
.Add "Word文件", "*.doc*;*.dot*;*.wps"
.Add "所有文件", "*.*"
End With
If .Show Then
Application.ScreenUpdating = False
num = .SelectedItems.Count
For Each file In .SelectedItems
Set word_temp = Documents.Open(file)
word_temp.Range.Copy
word_result.Range(word_result.Range.End - 1, word_result.Range.End).Select
DoEvents
Selection.Paste
Selection.InsertBreak
word_temp.Close wdDoNotSaveChanges
Next
Application.ScreenUpdating = True
End If
End With
Set word_result = Nothing
Set word_temp = Nothing
Set file_dialog = Nothing
str = Format(Timer - time_start, "均已成功合并;共用时0秒!")
str = Format(num, "您选择合并0个文件,") & str
MsgBox str, vbInformation, "文件合并结果"
End Sub
如下如所示
点击运行
选择需要合并的文件即可
快来试试吧☺️
如果对您有帮助,请您点赞、收藏、关注、转发
,让更多的人看到。
欢迎关注的我的小红书
跳转链接 👈点击即可跳转