pdf generation - Excel 2010 VBA to Use Acrobat Create PDF -
i have excel 2010 , acrobat xi pro. trying use vba create pdf file excel workbook multiple worksheets. need use create pdf function opposed activesheet.exportasfixedformat method because excel workbooks end being 50+ pages , need preserve internal workbook hyperlinks point various sections (i.e. worksheets) in workbook.
the best lead have been able find post: http://stackoverflow.com/questions/37551957/using-vba-how-do-i-call-up-the-adobe-create-pdf-function , post: https://forums.adobe.com/thread/853854
i can create empty pdf , insert pages source pdf. however, have been unable insert worksheet empty pdf. (i tried approach of starting pdf had 1 page already- same result). appears stuck assigning worksheet “object” pdf source. have been scouring google no luck… here vba code , appreciate feedback.
sub exportwithacrobat4() dim strfilename string dim objpddocnew object dim objpddoc object dim ninsertpageafter integer dim nstartpage integer dim nnumpages integer dim bbookmarks integer '********************************** strfilename = "e:\documents\work\document control\test1.pdf" set objpddocnew = createobject("acroexch.pddoc") if objpddocnew.create() = false 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 msgbox "could not open " & strfilename return end if nnumpages = objpddoc.getnumpages '--- add pages new file --- 'from acrobat sdk: 'variant_bool insertpages(long ninsertpageafter, lpdispatch ipddocsource, long nstartpage, long nnumpages, long bbookmarks); 'ninsertpageafter: page in current document after pages source document inserted. first page in pddoc object page 0. 'ipddocsource: lpdispatch acroexch.pddoc containing pages insert. ipddocsource contains instance variable m_lpdispatch, contains lpdispatch. 'nstartpage: first page in ipddocsource inserted current document. 'nnumpages: number of pages inserted. 'bbookmarks: if positive number, bookmarks copied source document. if 0, not. ninsertpageafter = -1 nstartpage = 0 bbookmarks = 1 '++++++++++++ excel stuff ++++++++++++ thisworkbook.sheets("sheet1").select 'need set worksheet = objpddoc somehow '+++++++++++++++++++++++++++++++++++++ if objpddocnew.insertpages(ninsertpageafter, objpddoc, nstartpage, nnumpages, bbookmarks) = false 'this works pdf file source msgbox "pages did not insert" exit sub end if 'save new file objpddocnew.save 1, "e:\documents\work\document control\testresult.pdf" objpddocnew.close msgbox "done" end sub
there no supported api pdfmaker add-ins. might find code people have tried, there no official documentation , change updates.
Comments
Post a Comment