Sub PDF_Proc()
'------------------------------------
'参照設定(Acrobat Proが必要)
'AcrobatまたはAdobe Acrobat 10.0 Type Library
'------------------------------------
Dim FSO As New Scripting.FileSystemObject
Dim Fol_Path1 As String
Dim Fol_Path2 As String
Dim PDF_Path1 As String
Dim PDF_Path2 As String
Dim PDF_SavePath As String
Dim New_Acro As New Acrobat.AcroPDDoc
Dim Acro_Join1 As New Acrobat.AcroPDDoc
Dim Acro_Join2 As New Acrobat.AcroPDDoc
Dim Page_Num1 As Long
Dim Page_Num2 As Long
Dim lRet As Long
Dim lPages As Long
'結合前
Fol_Path1 = "C:\Users\User\Desktop\VBA関連\VBA練習\PDF結合\結合前"
'結合後
Fol_Path2 = "C:\Users\User\Desktop\VBA関連\VBA練習\PDF結合\結合後"
PDF_Path1 = FSO.BuildPath(Fol_Path1, "テスト1.pdf")
PDF_Path2 = FSO.BuildPath(Fol_Path1, "テスト2.pdf")
PDF_SavePath = FSO.BuildPath(Fol_Path2, "保存.pdf")
'空のPDFファイルを作成する
lRet = New_Acro.Create()
lPages = 0
'PDFファイルを開く1
lRet = Acro_Join1.Open(PDF_Path1)
'ページ数を取得1
Page_Num1 = Acro_Join1.GetNumPages()
'空のPDFファイルに追加する
lRet = New_Acro.InsertPages(lPages - 1, Acro_Join1, 0, Page_Num1, False)
'PDFファイルを閉じる
lRet = Acro_Join1.Close()
lPages = lPages + Page_Num1
'-------------------------------------------
'PDFファイルを開く2
lRet = Acro_Join2.Open(PDF_Path2)
'ページ数を取得2
Page_Num2 = Acro_Join2.GetNumPages()
'PDFファイルを結合
lRet = New_Acro.InsertPages(lPages - 1, Acro_Join2, 0, Page_Num2, False)
'結合したPDFファイルを指定の場所に保存
lRet = New_Acro.Save(1, PDF_SavePath)
'PDFファイルを閉じる
lRet = Acro_Join2.Close()
'オブジェクト解放
Set New_Acro = Nothing
Set Acro_Join1 = Nothing
Set Acro_Join2 = Nothing
End Sub
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme