2017-08-15 4 views
0

Excel 2010とAcrobat XI Proがあります。私は複数のワークシートを持つExcelブックからPDFファイルを作成するためにVBAを使用しようとしています。 Excelブックは50以上のページになるので、ブックのさまざまなセクション(ワークシート)を指す内部ブックのハイパーリンクを保持する必要があるため、ActiveSheet.ExportAsFixedFormatメソッドとは対照的にCreate PDF関数を使用する必要があります。Excel 2010 VBAを使用してAcrobatを作成する

私は見つけることができた最高のリードは、この記事です:http://stackoverflow.com/questions/37551957/using-vba-how-do-i-call-up-the-adobe-create-pdf-function そして、このポスト:https://forums.adobe.com/thread/853854

私は成功し、空のPDFを作成し、別のソースPDFからページを挿入することができます。しかし、空のPDFにワークシートを挿入できませんでした。 (私はまた、すでに1ページの同じ結果を持ったPDFから始めるアプローチを試みました)。ワークシート「オブジェクト」をPDFソースに割り当てることができません。私は幸運とGoogleを精練しています...ここで私のVBAコードですと私は非常にフィードバックをいただければ幸いです。

Sub ExportWithAcrobat4() 
Dim strFileName As String 
Dim objPDDocNew As Object 
Dim objPDDoc As Object 
Dim nInsertPageAfter As Integer 
Dim nStartPage As Integer 
Dim nNumPages As Integer 
Dim bBookmarks As Integer 
'********************************** 

strFileName = "E:\Documents\WORK\Document Control\test1.pdf" 

Set objPDDocNew = CreateObject("AcroExch.PDDoc") 
If objPDDocNew.Create() = False Then 
    MsgBox "Did not create Combined PDF file.", vbCritical + vbOKOnly, "File Not Created" 
    Exit Sub 
End If 

Set objPDDoc = CreateObject("AcroExch.PDDoc") 
If objPDDoc.Open(strFileName) = False Then 
    MsgBox "Could not open " & strFileName 
    Return 
End If 
nNumPages = objPDDoc.GetNumPages 

'--- Add pages to new file --- 
'from Acrobat SDK: 
'VARIANT_BOOL InsertPages(long nInsertPageAfter, LPDISPATCH iPDDocSource, long nStartPage, long nNumPages, long bBookmarks); 
'nInsertPageAfter: The page in the current document after which pages from the source document are inserted. The first page in a PDDoc object is page 0. 
'iPDDocSource: The LPDISPATCH for the AcroExch.PDDoc containing the pages to insert. iPDDocSource contains the instance variable m_lpDispatch, which contains the LPDISPATCH. 
'nStartPage: The first page in iPDDocSource to be inserted into the current document. 
'nNumPages: The number of pages to be inserted. 
'bBookmarks: If a positive number, bookmarks are copied from the source document. If 0, they are not. 
nInsertPageAfter = -1 
nStartPage = 0 
bBookmarks = 1 

'++++++++++++ EXCEL STUFF ++++++++++++ 
ThisWorkbook.Sheets("Sheet1").Select 
'need to set the worksheet = objPDDoc somehow 
'+++++++++++++++++++++++++++++++++++++ 

If objPDDocNew.InsertPages(nInsertPageAfter, objPDDoc, nStartPage, nNumPages, bBookmarks) = False Then 'this works with a pdf file as source 
    MsgBox "Pages did not insert" 
    Exit Sub 
End If 

'save the new file 
objPDDocNew.Save 1, "E:\Documents\WORK\Document Control\testResult.pdf" 
objPDDocNew.Close 
MsgBox "done" 

End Subの

答えて

0

はのPDFMakerアドインへのサポートAPIはありません。人々が試したコードがいくつか見つかりますが、公式の文書はなく、更新によって変更される可能性があります。

関連する問題