将pdf文件与VBA和Foxit合并

将pdf文件与VBA和Foxit合并,vba,pdf,merge,foxit,Vba,Pdf,Merge,Foxit,我使用Foxit Phantompdf,完整的版本和访问权限。 在我们的程序中,我们必须保存多个pdf文件,其中一些文件在保存时应该合并到单个文件中。 这是我使用的代码 Dim phApp As PhantomPDF.Application Dim n1 As String Dim n2 As String n1 = "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf" n2 = "c:\Temp\f3769-190136-GROUPE OCÉAN- factu

我使用Foxit Phantompdf,完整的版本和访问权限。 在我们的程序中,我们必须保存多个pdf文件,其中一些文件在保存时应该合并到单个文件中。 这是我使用的代码

Dim phApp As PhantomPDF.Application

Dim n1 As String

Dim n2 As String

n1 = "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf"

n2 = "c:\Temp\f3769-190136-GROUPE OCÉAN- facture.pdf"

Set phApp = CreateObject("PhantomPDF.Application")

Dim phCreator As PhantomPDF.Creator

Set phCreator = phApp.Creator

***'Call phCreator.CombineFiles("c:\Temp\F3769-190136-GROUPE OCÉAN.pdf|c:\Temp\f3769-190136-GROUPE OCÉAN- facture.pdf", "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf", COMBINE_ADD_CONTENTS)***

Call phCreator.CombineFiles("""c:\Temp\" & n1 & "|'" & n2 & """" & ", " & """c:\Temp\F3769-190136-GROUPE OCÉAN.pdf"""" &", COMBINE_ADD_CONTENTS)

phApp.Exit
当我尝试使用完整的文件名(粗体)时,代码工作得非常好。 然而,当我尝试使用变量时,我得到一个

“参数不是可选的”

错误。 有人能帮我吗?
谢谢

呼叫线路中的字符串定义不正确

您已经用c:\temp定义了n1和n2,并且在字符串转换中再次添加了它。我不知道这是否是导致您的问题的原因

此外,我不知道这个phcreator.combine()实际需要的语法 但不可能只使用:

call pHcreator.combine(n1 & "|" & n2, …
“Argument not option”可能意味着您应该向pHcreator添加另一个输入,我猜这可能与FOXIT的合并功能页面设置有关。尝试在函数末尾添加一个输入变量整数,可能吗

但是,它在明文中编写字符串时工作的事实可能表明字符串操作是不正确的


我不是vba专业人士,但对结果感兴趣,我自己与Foxit合作,也希望与vba结合。我目前没有使用版本9 som,我似乎运气不好,只有升级它我才知道我想做什么。

我尝试过,但收到了相同的错误消息。因此,我利用了一个事实,即当文件名为纯文本时,函数可以工作。我将要合并的文件复制到一个临时文件夹中并重命名它们。重命名后的文件将在合并函数中使用。它工作得很好,但是Foxit添加了一个目录页,我还不知道如何删除它。以下是我的解决方案:

Private Sub Command4_Click()

Dim addi As String 'file to be merged to main file

Dim princi As String 'main file

Dim phApp As PhantomPDF.Application



'A temporary folder, in this case c:\t2, should be present

'In this example c:\Temp is the working folder



addi = "c:\Temp\filetomerge.pdf" 'full path of file to be merged

princi = "c:\Temp\mainfile.pdf" 'full path of main file



'fadd,pdf and fmain.pdf are the temporay files used in Foxit's function

FileCopy addi, "c:\t2\fadd.pdf" 'temporary file to be merged in temporary folder

FileCopy princi, "c:\t2\fmain.pdf" 'temporary main file in temporary folder



'Merge action

Set phApp = CreateObject("PhantomPDF.Application")

Dim phCreator As PhantomPDF.Creator

Set phCreator = phApp.Creator

Call phCreator.CombineFiles("c:\t2\fmain.pdf|c:\t2\fadd.pdf", "c:\t2\fmain.pdf", COMBINE_ADD_CONTENTS)



phApp.Exit



'Save merged file in working folder under main file name

Kill princi



FileCopy "c:\t2\fmain.pdf", princi



'delete temporary files

Kill "c:\t2\fadd.pdf"

Kill "c:\t2\fmain.pdf"

End Sub