The first file you have to open and to set as object. The other you have only to insert into the first file.
Attached a working example.
HTH, Reinhard
C:\AcInsFL4.vbs
----------------------------------------------------------------
REM: Insert single/multi Pdfs into one PDF, based on a filelist-file (Datei)
REM: The "Settings.." you can change to your needs. Drag&drop for 1 filelist-file accepted.
'*********Settings in File**************************
Datei = "C:\FileList.txt" '//Filename for filelist-file (files that will be inserted)
Ask = 0 '//0=don't ask for Insert;1=ask
Bookmark = 0 '//0=Insert No bookmarks;1=Insert based on Filename
InsWithBM = "false" '//true=Insert bookmarked files with BM; false = no
'****************************************************
set WshShell = CreateObject ("Wscript.Shell")
set fs = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
if objArgs.Count = 1 then Datei = ObjArgs(0)
Info = "Insert PDF-Files in Acrobat based on File-list-file."&VbCr&_
"File Name: "&Datei &" Start now?"
OK = MsgBox(Info, vbQuestion+vbYesNo,"Insert Files") : if OK = vbNo then WScript.quit
'//Start or switch to Acrobat
WshShell.run "Acrobat.exe"
While not WshShell.AppActivate("Adobe Acrobat") : Wscript.Sleep 1000 : Wend
Set gApp = CreateObject("AcroExch.App")
FLPOS = 1
if not fs.FileExists(datei) then
MsgBox "Ups! " & datei & " doesn't exist? " & "Try new!", vbExclamation
WScript.quit
end if
set dateiinhalt = fs.OpenTextFile(datei)
do until dateiinhalt.atEndOfStream
inhalt = dateiinhalt.ReadLine
if fs.FileExists(inhalt) then
if Ask=1 then if MsgBox(FlPos&": "&inhalt, vbOKCancel + vbInformation) = vbCancel then exit do
'#File->Open first File
if FLPOS = 1 then
Set gApp = CreateObject("AcroExch.App")
Set BASFL = CreateObject("AcroExch.pdDoc")
OK = BASFL.Open(INHALT)
if not OK Then if MsgBox("Error open Basic File") then Wscript.quit
BASFL.OpenAVDoc(mid(INHALT,InstrRev(INHALT,"\")+1))
WScript.Sleep 1000
Set avdoc = gApp.GetActiveDoc
Set pddoc = avdoc.GetPDDoc
Set jso = pddoc.GetJSObject
PageBAS = BASFL.GetNumPages-1
else
PageBAS = BASFL.GetNumPages
jso.pageNum = PageBAS+1
Set INSFL = CreateObject("AcroExch.PDDoc")
OK = INSFL.Open(INHALT)
if not OK Then if MsgBox("Error open InsertFile") then Wscript.quit
PageIns = INSFL.GetNumPages
OK = BASFL.InsertPages(PageBAS - 1,INSFL,0,PageIns,InsWithBM)
INSFL.Close
jso.pageNum = PageBAS+2
end if
if Bookmark = 1 then
BMNameIE = mid(Inhalt, InstrRev(Inhalt, "\")+1)
BMNameEE = left(BMNameIE, InstrRev(BMNameIE, ".")-1)
Set BMR = JSO.BookmarkRoot
BMR.CreateChild BMNameEE, "this.pageNum = " &PageBas, PageBas
end if
FLPOS = FLPOS+1
else '/-> file in Filelist (=inhalt) doesn't exist
Ok = MsgBox(Inhalt &vbCr &"File don't exist! - Continue?", vbQuestion+vbYesNo,"Insert Files")
if OK = vbNo then QUIT
end if
loop
MsgBox " DONE!" &vbCr &"Don't forget to save the File (save as)"
QUIT
Sub QUIT
dateiinhalt.close
Set JSO=Nothing
Set PDDoc=Nothing
Set gApp=Nothing
Wscript.quit
End sub