[已解决]求高手修改下这个word文档合并的VBS代码
本帖最后由 king8462 于 2017-8-25 21:24 编辑vbs代码如下:
Call CombinAllDocFiles("D:\doc", "D:\Combined.doc")
Sub CombinAllDocFiles(strRootPath, strTargetFileName)
On Error Resume Next
Dim oApp, fso, oFolder, oFile
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.Documents.Add
oApp.ActiveWindow.View.Type = 2 ' wdOutlineView
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(strRootPath)
For Each 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, , 1
oApp.Selection.Bookmarks("\Page").Range.Delete
oApp.ActiveDocument.SaveAs strTargetFileName
oApp.Quit True
Set oApp = Nothing
MsgBox "完成!"
End Sub 我自己瞎改了一部分,但有几句不会搞:#include <Word.au3>
$hb="d:\1.doc"
Global $word = ObjCreate("word.application")
$word.visible = True
$word.Documents.Add
$word.ActiveWindow.View.Type = 2 ' wdOutlineView
Global $fso = ObjCreate("Scripting.FileSystemObject")
Global $oFolder = $fso.GetFolder("d:\doc")
For Each oFile In $oFolder.Files
$word.ActiveDocument.Subdocuments.AddFromFile oFile.Path
Next
$word.ActiveDocument.Subdocuments.Delete
$word.ActiveWindow.View.Type = 3 ' wdPrintView
$word.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1" '跳转到第1页
$word.Selection.Bookmarks("\Page").Range.Delete
$word.ActiveDocument.SaveAs $hb
$word.Quit True @kevinch 老师看看 本帖最后由 king8462 于 2017-8-25 09:09 编辑
懂word对象的高手帮忙看看啊。 FuncCombinAllDocFiles($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经测试通过 wdGoToPage 的值为1 回复 5# h20040606
高手,多谢了! h20040606 发表于 2017-8-25 16:09
经测试通过
合并后页眉的格式丢失
页:
[1]