本帖最后由 hlzxcjx 于 2026-3-5 12:59 编辑
这个脚本合并word文档后,最后多出一页空白,怎样改脚本可以去掉最后一页空白呢?
$i=1
FileDelete(@ScriptDir & "\合并.doc")
$path=@ScriptDir & "\word"
$all=DirGetSize($path,1)
$all=$all[1]
CombinAllDocFiles($path, @ScriptDir & "\合并.doc")
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)
ToolTip("第" & $i & "页")
$i=$i+1
If $i>$all Then ExitLoop
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,"$i=" & $i & " $all=" & $all, "已全部合并!")
EndFunc
|