以下是引用flyrob在2007-12-16 12:25:51的发言:我要合并的rtf文档的文件名为 1.rtf 2.rtf ......600.rtf 非常感谢 匆匆做了一个,请测试一下: '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2007-12-16 12:41:25 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0287^The Code CopyIn [ThisDocument-ThisDocument]^' '* ----------------------------- Option Explicit Option Compare Binary Sub InsertFiles() Dim MyDialog As FileDialog, vrtSelectdeItem As Variant, Doc As Document Dim oFile As Variant, myArray() As String, N As Integer, i As Integer, j As Integer Dim TempA As String, myRange As Range ' On Error Resume Next '检查是否为空 '定义一个文件夹选取对话框 Set MyDialog = Application.FileDialog(msoFileDialogFilePicker) With MyDialog .Filters.Clear '清除所有文件筛选器中的项目 .Filters.Add "所有 WORD 文件", "*.doc;*.rtf", 1 '增加筛选器的项目为所有WORD文件 .AllowMultiSelect = True '允许多项选择 If .Show = -1 Then '确定 For Each oFile In .SelectedItems '在所有选取项目中循环 ReDim Preserve myArray(N) myArray(N) = oFile N = N + 1 ' Set Doc = Documents.Open(FileName:=vrtselecteditem, Visible:=False) Next End If End With N = N - 2 For i = 0 To N - 1 For j = i + 1 To N If myArray(i) > myArray(j) Then TempA = myArray(j) myArray(j) = myArray(i) myArray(i) = TempA End If Next j Next i For Each oFile In myArray ' Debug.Print oFile With ActiveDocument.ActiveWindow.Selection .InsertFile FileName:=oFile, ConfirmConversions:=False .InsertParagraphAfter .InsertBreak Type:=wdSectionBreakNextPage .Collapse Direction:=wdCollapseEnd End With Next End Sub '----------------------
|