Hi,
Which part of the code tells the program to insert the
rest of the files in the folder after the summary and
report files are inserted?
None, as you didn't ask for that feature.
As a result, I'd say, the code doesn't look superb,
but should do, what you wanted.
Sub Test555()
Dim i As Integer
Dim s As String ' a filename including path
Selection.WholeStory
Selection.Collapse direction:=wdCollapseEnd
With Application.FileSearch
.NewSearch
.LookIn = "c:\test"
.FileName = "*.doc"
.Execute
For i = 1 To .FoundFiles.Count
If InStr(.FoundFiles(i), "summary") Then
Selection.InsertFile FileName:=.FoundFiles(i)
End If
Next
For i = 1 To .FoundFiles.Count
If InStr(.FoundFiles(i), "report") Then
Selection.InsertFile FileName:=.FoundFiles(i)
End If
Next
For i = 1 To .FoundFiles.Count
s = .FoundFiles(i)
If InStr(s, "summary") = 0 _
And InStr(s, "report") = 0 _
And InStr(s, "~") = 0 Then
Debug.Print .FoundFiles(i) ' for testing
'Selection.InsertFile FileName:=.FoundFiles(i)
' remove ' for inserting
' InStr(s, "~") is there to avoid trying
' to insert temporary files, which may cause
' problems
End If
Next
End With
End Sub