找回密码
 加入
搜索
查看: 155|回复: 2

[系统综合] au3合并文档问题

[复制链接]
发表于 2026-3-5 13:00:11 | 显示全部楼层 |阅读模式
本帖最后由 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


 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2026-3-6 11:44:30 | 显示全部楼层
把If $i>$all Then ExitLoop 改成 $i>=$all 试试
 楼主| 发表于 2026-3-6 11:48:29 | 显示全部楼层
fybhwsx 发表于 2026-3-6 11:44
把If $i>$all Then ExitLoop 改成 $i>=$all 试试

试过不行!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2026-4-26 09:01 , Processed in 0.060211 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表