打开Microsoft Word。
按Alt+F11 打开VBA编辑器。
插入模块:点击“插入”->“模块”。
粘贴以下代码:
Sub MergeDocuments() Dim baseDoc As Document Dim fileDialog As FileDialog Dim selectedFiles As FileDialogFilters Dim i As Integer ' Create a new document Set baseDoc = Documents.Add ' Open the file dialog Set fileDialog = Application.FileDialog(msoFileDialogFilePicker) fileDialog.AllowMultiSelect = True fileDialog.Filters.Clear fileDialog.Filters.Add "Word Documents", "*.docx; *.doc" ' Show the dialog If fileDialog.Show = -1 Then For i = 1 To fileDialog.SelectedItems.Count ' Insert each selected file Selection.InsertFile fileDialog.SelectedItems(i) ' Add a page break after each document Selection.InsertBreak Type:=wdPageBreak Next i End If End Sub
运行宏:
按F5运行宏,选择你要合并的文件。
以上内容如果对你有用,请收藏。
评论列表: