S
sals
Hi there,
I'm using this code to concatenate many files into one.
I keep getting an extra page at the beggining.
What am I doing wrong?
Thanks,
S
Sub concatFiles()
Dim resp As Integer
Dim activeDir As String
Dim fileType As String
resp = MsgBox("This macro concatenates all DOC files in the
directory you select next.", vbOKCancel)
If resp = vbCancel Then Exit Sub
fileType = "doc"
If activeDir = "" Then
activeDir = "F:\Doc" 'getFullPath(UCase(fileType) & "|*." &
UCase(fileType))
End If
If activeDir <> "" Then
With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*." & fileType
.MatchTextExactly = False
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Selection.InsertBreak Type:=wdSectionBreakOddPage
Selection.InsertFile FileName:=.FoundFiles(i),
Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
Next i
Else
MsgBox "There were no files found to concatenate."
End If
End With
Else
Exit Sub
End If
MsgBox "Concatenated " & i - 1 & " files."
End Sub
I'm using this code to concatenate many files into one.
I keep getting an extra page at the beggining.
What am I doing wrong?
Thanks,
S
Sub concatFiles()
Dim resp As Integer
Dim activeDir As String
Dim fileType As String
resp = MsgBox("This macro concatenates all DOC files in the
directory you select next.", vbOKCancel)
If resp = vbCancel Then Exit Sub
fileType = "doc"
If activeDir = "" Then
activeDir = "F:\Doc" 'getFullPath(UCase(fileType) & "|*." &
UCase(fileType))
End If
If activeDir <> "" Then
With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*." & fileType
.MatchTextExactly = False
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Selection.InsertBreak Type:=wdSectionBreakOddPage
Selection.InsertFile FileName:=.FoundFiles(i),
Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
Next i
Else
MsgBox "There were no files found to concatenate."
End If
End With
Else
Exit Sub
End If
MsgBox "Concatenated " & i - 1 & " files."
End Sub