|
你没有说每个文档要分开,加个分页符就可以了
Sub 合并子文件夹下文档()
Dim filesys As Object, drv As Object, fd As FileDialog
Dim wd As Document, wd1 As Document, w$, s$, m$, k%
Application.ScreenUpdating = False
Set filesys = CreateObject("scripting.filesystemobject")
Set fd = Application.FileDialog(4)
fd.AllowMultiSelect = True
fd.Show '请选择子文件夹的上一级文件夹,获得父文件夹路径
On Error Resume Next
s = fd.InitialFileName
For Each drv In filesys.GetFolder(s).SubFolders
If drv.Size > 0 Then
m = drv.Name
n = filesys.GetFolder(s & m & "\").Files.Count
Set wd = Documents.Add
End If
w = Dir(s & m & "\*.doc?")
k = 0
Do
k = k + 1
If InStr(w, ".doc") > 0 Then
Set wd1 = Documents.Open(s & m & "\" & w)
With wd1
.Range.Copy
.Close 0
End With
Selection.Paste
If k < n Then Selection.TypeText Chr(12)
End If
w = Dir
Loop Until w = ""
wd.SaveAs2 (s & m & ".docx")
wd.Close
Next drv
Set fd = Nothing
Set filesys = Nothing
Application.ScreenUpdating = True
End Sub
|
|