Word合并VBA代码

Sub DocMerge() \'\'\' 合并多个文档 \'\'\'用法:先创建一个目标文档,依次加入源文件,最后保存 \'\'\'by:CMooon \'\'\'2012.02.26 Dim myDialog As FileDialog Dim i As Long Const wdPageBreak = 7 \' 分页符 Set myDialog = Application.FileDialog(msoFileDialogFilePicker) With myDialog .Title = "请选择要合并的文档(可以多选)" .AllowMultiSelect = True .Filters.Clear .Filters.Add "所有 WORD 文件", "*.doc", 1 End With On Error Resume Next If myDialog.Show <> -1 Then Exit Sub For i = 1 To myDialog.SelectedItems.count Selection.InsertFile FileName:=myDialog.SelectedItems(i) Selection.InsertBreak wdPageBreak MsgBox myDialog.SelectedItems(i) & " 成功合并!" Next End Sub

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgfxzd.html