|
* 楼主,如果要手动选择文件的话,请右键 WinRAR 打包到某盘,解压到文件夹中,再应用宏(执行宏后会询问打开哪个文件夹,只要找到要合并的文件夹即可确定)。
* 如果想选择某个文件夹(可以包含子文件夹)下的所有文件合并的话,请试用由 杜老师(duquancai)编写的《循环遍历文件夹及子文件夹》宏完成你的任务。
* 请注意备份原文件。
- Sub TextJoint_LoopFolder_duquancai()
- Dim pPath$, f As Object, fd As Object, fso As Object, Stack$(), top&, n&, stxt$, doc As Document, x&
- pPath = SelectFolder
- Set fso = CreateObject("Scripting.FileSystemObject")
- top = 1
- ReDim Stack(0 To top)
- Documents.Add
- Dim InsFileName$
- Do While top >= 1
- For Each f In fso.getfolder(pPath).Files
- n = n + 1
- stxt = f.Path
- If stxt Like "*.doc*" Then
- Set doc = Documents.Open(FileName:=stxt)
- InsFileName = doc.FullName
- doc.Close SaveChanges:=wdSaveChanges
- Selection.InsertFile FileName:=InsFileName
- Selection.InsertBreak Type:=wdSectionBreakNextPage
- x = x + 1
- End If
- Next
- For Each fd In fso.getfolder(pPath).SubFolders
- Stack(top) = fd.Path
- top = top + 1
- If top > UBound(Stack) Then ReDim Preserve Stack(0 To top)
- Next
- If top > 0 Then pPath = Stack(top - 1): top = top - 1
- Loop
- Set f = Nothing
- Set fd = Nothing
- Set fso = Nothing
- MsgBox "File not saved! Processed Files = " & n & vbCr & "Total Files(*.docx/*.doc) = " & x, 0 + 16
- End Sub
- Function SelectFolder() As String
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then SelectFolder = .SelectedItems(1) & "" Else End
- End With
- If MsgBox("Are you sure ? " & """" & SelectFolder & """", 4 + 16) = vbNo Then End
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|