Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to Merge 2 PDF files not working - Please help

Status
Not open for further replies.

Flo79

Technical User
Nov 12, 2002
80
US
Hi,

I have two PDF files, "PDF_1" and "PDF_2".

I want to write VBA code that merges PDF_1 with PDF_2, then saves PDF_2 (which now should be a product of both files)

Here is the code that I have been able to gather:

It does absolutely nothing for some odd reason.
---------------------------------
Option Explicit

Public Function Test()

Dim PDF_1_Name, File_Path, PDF_2_Name, File_Ext As String

Dim AcroExchApp As Acrobat.CAcroApp
Dim AcroExchPDDoc As Acrobat.CAcroPDDoc
Dim AcroExchInsertPDDoc As Acrobat.CAcroPDDoc
Dim iNumberOfPagesToInsert, iLastPage As Integer


Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")

File_Ext = ".pdf"
File_Path = "C:\Documents and Settings\Administrator\Desktop\Attachments"
PDF_2_Name = "" & File_Path & "\" & "PDF_2" & "" & File_Ext & ""
PDF_1_Name = "C:\Documents and Settings\Administrator\Desktop\Attachments\Originals\PDF_1.pdf"




AcroExchPDDoc.Open (PDF_2_Name)

AcroExchApp.Show

iLastPage = AcroExchPDDoc.GetNumPages()

Set AcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")
AcroExchInsertPDDoc.Open (PDF_1_Name)
iNumberOfPagesToInsert = AcroExchInsertPDDoc.GetNumPages

AcroExchPDDoc.InsertPages iLastPage, AcroExchInsertPDDoc, 0, iNumberOfPagesToInsert, True

AcroExchInsertPDDoc.Close

AcroExchPDDoc.Save &H1, "PDF_2_Name"

AcroExchPDDoc.Close
AcroExchApp.Exit

End Function

----------------------------------

Any help would be greatly appreciated.

Thanks in Advance!

Regards

FGP

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top