自己参考网上的资料写的,批量合并同一文件夹下doc和docx文件的宏,用的就是插入文件内容的方式[Visual Basic] 纯文本查看 复制代码 Sub 宏1()
'
' 宏1 宏
'
'
' MyPath = ActiveDocument.Path
MyPath = InputBox("请指定待插入的word文件所在的文件夹。", "消息", Application.Path)
ChangeFileOpenDirectory MyPath
MyName = Dir(MyPath & "\" & "*.doc")
i = 0
Do While MyName <> ""
If MyName <> ActiveDocument.Name Then
Selection.InsertBreak Type:=wdPageBreak
Selection.InsertFile FileName:=MyName, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
i = i + 1
End If
MyName = Dir
Loop
MyName = Dir(MyPath & "\" & "*.docx")
i = 0
Do While MyName <> ""
If MyName <> ActiveDocument.Name Then
Selection.InsertBreak Type:=wdPageBreak
Selection.InsertFile FileName:=MyName, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
i = i + 1
End If
MyName = Dir
Loop
End Sub |