Func CombinAllDocFiles($strRootPath, $strTargetFileName)
Local $wdGoToPage=1
Dim $oApp, $fso, $oFolder, $oFile
$oApp = ObjCreate("Word.Application")
$oApp.Visible = True
$oApp.Documents.Add
$oApp.ActiveWindow.View.Type = 2 ; wdOutlineView
$fso = ObjCreate("Scripting.FileSystemObject")
$oFolder = $fso.GetFolder($strRootPath)
For $oFile In $oFolder.Files
$oApp.ActiveDocument.Subdocuments.AddFromFile($oFile.Path)
Next
$oApp.ActiveDocument.Subdocuments.Delete
$oApp.ActiveWindow.View.Type = 3 ; wdPrintView
$oApp.Selection.GoTo($wdGoToPage, Default, 1)
$oApp.Selection.Bookmarks("\Page").Range.Delete
$oApp.ActiveDocument.SaveAs($strTargetFileName)
$oApp.Quit(True)
$oApp = 0
MsgBox(0,"", "完成!")
EndFunc
经测试通过 |